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

相关推荐
全栈若城4 分钟前
HarmonyOS Pen Kit 实战:手写笔轻捏、双击与取色器完整集成
华为·harmonyos·手写笔·harmonyos6
bestcxx11 分钟前
多个维度对 Java、Python、C#、Go 这四种主流编程语言进行比较
java·python·c#
装杯让你飞起来啊11 分钟前
Kotlin 条件判断 if / when 与智能转换 smart cast
开发语言·python·kotlin
计算机毕业编程指导师40 分钟前
【大数据毕设推荐】Hadoop+Spark电影票房分析系统,Python+Django全栈实现 毕业设计 选题推荐 毕设选题 数据分析 机器学习 数据挖掘
大数据·hadoop·python·计算机·spark·毕业设计·电影票房
唐叔在学习1 小时前
TodoList:我的待办助手
python·程序员·ai编程·待办应用
郝学胜-神的一滴1 小时前
深度学习损失函数:从原理到实战之 Smooth L1 Loss
人工智能·pytorch·python·深度学习·机器学习·数据挖掘
hhzz2 小时前
第1天:初识Python
开发语言·python·学习编程
黄粱梦醒2 小时前
UV快速搭建新项目
python
小学生-山海2 小时前
【YOLO系列】基于YOLOv8/v11/v26与tkinter的车流量统计系统设计
python·yolo
szial2 小时前
Python Click 教程:从函数到专业命令行工具
开发语言·python