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

相关推荐
风华圆舞38 分钟前
鸿蒙HarmonyOS滚字组件实战 —— 逐字 Slot Roll,从浏览器到原生 ArkUI
华为·harmonyos·arkui·slottext·measureutils·共享时间轴·滚字
不羁的木木1 小时前
HarmonyOS APP实战-画图APP - 第8篇:图像效果应用(亮度/模糊/灰度)
华为·harmonyos
花花无缺1 小时前
Windows 定时执行 Python 脚本方案
python·操作系统·命令行
●VON1 小时前
HarmonyKit | 鸿蒙开发展望:HarmonyKit 未来路线图与社区共建
华为·单元测试·harmonyos·鸿蒙
不羁的木木2 小时前
HarmonyOS APP实战-画图APP - 第3篇:矩形与圆形绘制
华为·harmonyos
流云鹤2 小时前
1. 配置环境、创建导航栏
python·django
三亚兴嘉装饰2 小时前
准备在三亚装房子找哪家装修
python
绝世番茄3 小时前
Column 与 if/else 条件渲染:动态子组件的布局行为
华为·harmonyos·鸿蒙
Mx_coder3 小时前
8年Java开发者AI转型第二周:RAG系统深入 + 向量数据库实战(Day 8-10)
python
ximen502_3 小时前
Python 语言知识总结
开发语言·python