华为机考入门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 软件工程小施同学

相关推荐
老前端的功夫21 分钟前
【Java从入门到入土】47:构建工具:Maven与Gradle的战争
java·python·maven
yang_coder37 分钟前
juypter notebook启动ssl报错的处理记录
python·jupyter
最爱老式锅包肉1 小时前
《HarmonyOS技术精讲-ArkWeb》进阶配置:自适应与交互控制
华为·交互·harmonyos
最爱老式锅包肉1 小时前
《HarmonyOS技术精讲-Core Speech Kit(基础语音服务)》第5篇:实战项目——构建全功能语音助手
华为·harmonyos
江华森1 小时前
exp01_Python_数据类型
开发语言·python
大鱼>2 小时前
模型可解释性:特征重要性/SHAP/LIME
人工智能·python·机器学习·lstm
代码不接地2 小时前
【时间序列预测】0.时间序列任务知识地图
python·ai编程
我是小a2 小时前
鸿蒙 ArkUI 数据可视化图例对照表:组件化设计与实现
华为·信息可视化·harmonyos·鸿蒙·鸿蒙系统
许彰午2 小时前
77_Python数据清洗实战技巧
开发语言·python