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

相关推荐
Yolanda_202220 分钟前
Python学习-第九部分-错误处理与异常处理
开发语言·python·学习
这个人懒得名字都没写1 小时前
Flask + PyArmor Gunicorn启动报错:RuntimeError: unauthorised use of script
python·flask·gunicorn·pyarmor
C++、Java和Python的菜鸟1 小时前
第10章 后端Web进阶(Maven高级)
开发语言·python
暗黑小白1 小时前
路由策略与引擎可替换性
后端·python·ai agent
小罗水2 小时前
第 20 章 高级 RAG 技术与检索优化
人工智能·python·机器学习
bamb002 小时前
一个项目带你入门AI应用开发06
python
liwulin05062 小时前
【ESP32S3】调用百度云语音合成接口后重启
python
m沐沐2 小时前
【机器学习】矿物识别系统实战——六种填充方法×六种模型全面对比
人工智能·python·深度学习·机器学习·矿物识别
软糖姐姐2 小时前
Python:__closure__ 详解
python·闭包·__closure__·自由变量·cell对象
月光船幽幽2 小时前
四层公理框架驱动AI健康诊断
人工智能·python·科技·算法·安全