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

相关推荐
qq_372154234 分钟前
CSS如何改变单个网格项目的对齐方式
jvm·数据库·python
kexnjdcncnxjs5 分钟前
CodeIgniter4安全加固指南:防御XSS与CSRF攻击
jvm·数据库·python
2401_871492855 分钟前
Imagick PDF 处理失败的常见原因与解决方案
jvm·数据库·python
littleM7 分钟前
深度拆解 HermesAgent(六):研究功能与测试体系
开发语言·人工智能·python·架构·ai编程
CHANG_THE_WORLD10 分钟前
使用python调用podofogc文件 批量处理 pdf文件
windows·python·pdf
隔壁大炮10 分钟前
CNN图像分类案例
人工智能·pytorch·python·深度学习·算法·分类·cnn
Lanren的编程日记12 分钟前
Flutter 鸿蒙应用智能提示系统实战:上下文感知+新手引导+操作提示,打造极致用户体验
flutter·华为·harmonyos·ux
深邃-15 分钟前
【Web安全】-Kali,Linux配置(2):Java环境配置,Python环境配置,Conda使用,PIP配置使用,SSH远程登录
java·linux·python·安全·web安全·网络安全·php
枫叶丹415 分钟前
【HarmonyOS 6.0】Call Service Kit VoIP接口Wearable设备支持详解:从手机到手表,VoIP通话的全场景延伸
开发语言·华为·智能手机·harmonyos
Lanren的编程日记16 分钟前
Flutter 鸿蒙应用智能搜索功能实战:模糊搜索+搜索建议+搜索历史,打造极致搜索体验
flutter·华为·harmonyos