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

相关推荐
拉格朗日(Lagrange)几秒前
【第2 章】WorkBuddy 从入门到高手
开发语言·python
花花_111 分钟前
HarmonyOS 7 状态手记 01|页面状态别乱放
华为·harmonyos
老歌老听老掉牙1 小时前
斜抛运动问题分析:给定最大高度与墙面位置的轨迹与时间求解
python·斜抛运动
言乐61 小时前
Python自动去除水印
开发语言·python·django·virtualenv·pygame
czq_26867194871 小时前
Python打卡第31天
开发语言·python
invicinble1 小时前
python 编程语言 认识维度
开发语言·数据库·python
李游Leo1 小时前
HarmonyOS 7 AVSession + Float Window:闪控窗播放控制权的会话移交与重复指令去重【鸿蒙心迹】
华为·harmonyos
AC赳赳老秦1 小时前
数据采集全链路审计留痕:用 OpenClaw 实现合规审计与追溯
开发语言·汇编·python·php·swift·deepseek·openclaw
李游Leo1 小时前
HarmonyOS 7 + ArkTS-UDMF:精准碰一碰载荷的协议版本协商与字段降级【鸿蒙心迹】
华为·harmonyos
张铁霖2 小时前
深度解析:AI三次浪潮与机器学习三种范式,
python