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

相关推荐
Swift社区几秒前
鸿蒙 App 卡顿分析:定位方法 + 优化代码实战
华为·harmonyos
俊俊谢2 分钟前
[python]FastAPI + 自建SSE 踩坑全记录
开发语言·python·fastapi
至乐活着10 分钟前
Python异步编程asyncio完全指南:从入门到高性能实战
python·并发·协程·asyncio·异步编程
functionflux26 分钟前
kafka-python:Python 生态中最成熟的 Kafka 客户端
分布式·python·其他·kafka
帅小伙―苏33 分钟前
239. 滑动窗口最大值
python·力扣
爱吃苹果的梨叔1 小时前
2026年KVM over IP采购指南:BIOS级接管、并发和审计怎么验收
ide·python·tcp/ip·github
Cloud_Shy6181 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第六章 Item 40 - 43)
android·开发语言·人工智能·笔记·python·学习方法
装不满的克莱因瓶1 小时前
掌握生成对抗网络(GAN)的优化目标与评估指标——从博弈函数到生成质量衡量体系
人工智能·python·深度学习·算法·机器学习
半只小闲鱼1 小时前
配置计划模块通用办公设备家具批复数合计计算
开发语言·python
是阿千呀!1 小时前
A股市场风格切换研究:基于 Barra 风险模型的量化框架
python·量化