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

相关推荐
狐狐生风几秒前
Python UV 完整安装教程
开发语言·python·uv
new【一个】对象几秒前
Python 包管理器uv
人工智能·windows·python
m0_591364731 分钟前
Python如何进行数据平滑处理_使用Pandas滚动中位数计算
jvm·数据库·python
chen_ever6 分钟前
大模型学习规划
人工智能·python·学习
彳亍1019 分钟前
mysql主从复制和双主复制有什么区别_mysql架构对比
jvm·数据库·python
a7963lin9 分钟前
MySQL数据库提示表损坏怎么修复_使用REPAIR TABLE修复方案
jvm·数据库·python
dFObBIMmai10 分钟前
如何撤销PUBLIC的危险权限_REVOKE EXECUTE ON UTL_FILE
jvm·数据库·python
2501_9012005311 分钟前
CSS如何优化移动端CSS选择器性能_遵循BEM规范避免过长嵌套
jvm·数据库·python
ㄟ留恋さ寂寞12 分钟前
如何用事务 Transaction 确保 IndexedDB 多表操作的安全性
jvm·数据库·python
m0_4954964112 分钟前
html标签怎样表示强调_em和i标签语义差异说明【操作】
jvm·数据库·python