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

相关推荐
XY_墨莲伊12 小时前
【编译原理】实验二:基于有穷自动机FA词法分析器设计与实现
c语言·开发语言·c++·python
qq_4523962312 小时前
【工程实战】第三篇:接口自动化 —— Requests 的工业级封装:Session 关联、日志与断言
python·自动化
2401_8971905512 小时前
html标签怎么设置段落间距_p标签默认样式及调整建议【指南】
jvm·数据库·python
Java面试题总结12 小时前
BCrypt密码加密
开发语言·python
2301_8035389512 小时前
如何修改Oracle用户密码_ALTER USER IDENTIFIED BY重置口令
jvm·数据库·python
NotFound48613 小时前
Golang方法值接收者和指针接收者区别_Golang方法接收者教程【实战】
jvm·数据库·python
m0_6403093013 小时前
Golang Gin怎么绑定JSON参数_Golang Gin JSON绑定教程【精通】
jvm·数据库·python
databook13 小时前
用Manim实现动态交点计算--从一个动点问题说起
python·动效
2301_7641505613 小时前
CSS如何用Less实现多维度的样式复用_结合混合与继承技术实现
jvm·数据库·python
清平乐的技术专栏13 小时前
Python依赖包实现window下载上传到Linux
linux·开发语言·python