华为机考入门python3--(0)模拟题2-vowel元音字母翻译

分类:字符串

知识点:

  1. 字符串转list,每个字符成为list中的一个元素 list(string)

  2. 字符串变大小写 str.upper(), str.lower()

题目来自【华为招聘模拟考试】

python 复制代码
# If you need to import additional packages or classes, please import here.

def func():

    # please define the python3 input here. For example: a,b = map(int, input().strip().split())
    sentence = input().strip()
    my_list = list(sentence)
    # ['w', 'h', 'o', ' ', 'l', 'o', 'v', 'e']
    # print(my_list)
    
    vowels = ('a','e','i','o','u','A','E','I','O','U')
    new_my_list = []
    for letter in my_list:
        if letter in vowels:
            new_my_list.append(letter.upper())
        elif letter == ' ':
            new_my_list.append(letter)
        else:
            new_my_list.append(letter.lower())
    
    # print(new_my_list)
    new_sentence = ''.join(new_my_list)
    print(new_sentence)
    # please finish the function body here.
    # please define the python3 output here. For example: print().

if __name__ == "__main__":
    func()

by 软件工程小施同学

相关推荐
m0_67848545几秒前
CSS实现浮动图标与文本居中对齐_配合浮动与flex
jvm·数据库·python
YuanDaima20482 分钟前
二分查找基础原理与题目说明
开发语言·数据结构·人工智能·笔记·python·算法
2401_887724508 分钟前
uni-app动画效果实现 uni-app如何使用animation API
jvm·数据库·python
Luca_kill9 分钟前
实战指南:用 Python + NLP 搭建一套轻量级 AI 舆情监控系统
人工智能·python·机器学习·nlp·舆情监控
七颗糖很甜10 分钟前
python实现全国雷达拼图数据的SCIT风暴识别
python·算法·scipy
m0_7488394910 分钟前
mysql如何处理不走索引的OR查询_使用UNION ALL优化重写
jvm·数据库·python
Dxy123931021614 分钟前
将 PyTorch Tensor 转换为 Python 列表
人工智能·pytorch·python
2401_8877245023 分钟前
在 Ubuntu Core 上部署 Go Web 服务的完整实践指南
jvm·数据库·python
Polar__Star28 分钟前
C#怎么实现Redis分布式缓存 C#如何在ASP.NET Core中集成Redis实现分布式缓存方案【架构】
jvm·数据库·python
2301_8009769332 分钟前
python的协程
开发语言·python