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

相关推荐
MC皮蛋侠客18 小时前
Ruff 完全指南:下一代 Python Linter 与 Formatter
python
不爱学英文的码字机器18 小时前
[鸿蒙PC命令行移植适配]移植rust三方库tokei到鸿蒙PC的完整实践
华为·rust·harmonyos
以太浮标18 小时前
华为eNSP模拟器综合实验之- 路由黑洞场景解析及实验
运维·网络·网络协议·网络安全·华为·智能路由器·信息与通信
EterNity_TiMe_18 小时前
[鸿蒙PC命令行移植适配]移植rust三方库ouch到鸿蒙PC的完整实践
华为·rust·harmonyos
提子拌饭13318 小时前
路径动画用鸿蒙PC用Electron框架实现流动效果技术详解
华为·electron·开源·harmonyos·鸿蒙
happylifetree18 小时前
Python014-第二章13.数据容器-tuple案例
python
jingyu飞鸟19 小时前
openEuler 22.03 LTS SP4安装华为opengauss 22.03 LTS版本数据库,一键复制安装使用,保姆级教程
数据库·华为
茉莉玫瑰花茶19 小时前
LangGraph 其他核心能力 [ 3 ]
python·ai
AI玫瑰助手19 小时前
Python函数:递归函数的定义与阶乘案例实现
开发语言·python·信息可视化
李二。19 小时前
鸿蒙原生ArkTS通讯录管家实战开发详解
华为·harmonyos