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

相关推荐
王志来1379447300818 分钟前
从分散到集成:工控服务器机箱采购如何实现“一站式”破局
运维·服务器·人工智能·python
三十岁老牛再出发33 分钟前
08.18每日总结
c++·python·numpy·pandas
️学习的小王1 小时前
Anaconda国内镜像配置与conda常用命令
ide·经验分享·python·conda
Zane19941 小时前
daemon 线程说没就没?一文讲透 threading 的适用场景与线程安全
后端·python
up up day1 小时前
Python enchant 模块使用教程
python
zoujiahui_20181 小时前
Python 包与环境管理工具 uv
开发语言·python·uv
Magic-ZYJ1 小时前
HarmonyOS 调用系统文件保存器导出 JSON 与 CSV
华为·json·harmonyos·鸿蒙·独立开发者
程序猿阿森2 小时前
Python 闭包与装饰器:从入门到精通
开发语言·python·面试
老大白菜2 小时前
Qwen3.8-27B 本地推理 + DeepSeek Harness 配置
python·qwen·deepseek·harness
Code额2 小时前
Python 连接 DeepSeek API,OpenAI 对话方式总结
后端·python·ai·ai编程