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

相关推荐
less_1213824 分钟前
HarmonyOS WPS Open SDK:打开时配置水印与修订模式
华为·harmonyos·wps
matlabgoodboy2 小时前
计算机毕设代做|Java Python Matlab APP 全套开发设计
java·python·课程设计
用户8356290780513 小时前
Python Word 转 PDF 和 PDF 转 Word 指南
后端·python
用户8356290780513 小时前
如何使用 Python 加密和保护 Word 文档
后端·python
Fluxproxy3 小时前
AI数据集采集、批量模型推理报错频发?AI项目网络稳定性优化实战
python·ai·ai编程
Fanta丶4 小时前
10.Python class类的定义和魔术方法
python
小玮看世界5 小时前
[Python]从“脏”数据到优雅实现:一个IoT滑动窗口最大值问题的测试驱动优化实录
linux·前端·python
MC皮蛋侠客6 小时前
SQLAlchemy 系列(十一):从 1.x 到 2.x——渐进迁移与数据访问层治理
数据库·python
魔镜前的帅比6 小时前
(开源项目)x-claw (设计)
python·ai·rust·开源
风起洛阳@不良使6 小时前
springmvc中Model和ModelAndView
开发语言·python