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

相关推荐
逻极11 分钟前
FastAPI 实战:从入门到自动化文档,如何把API开发效率提升200%
python·api·fastapi·swagger·异步
小雨青年37 分钟前
【HarmonyOS 7开发者前瞻】10 HarmonyOS 7 真实项目适配路线图:API 26、AI / Agent 与多端改造优先级
人工智能·华为·harmonyos
半兽先生42 分钟前
大模型技术开发与应用——5.大模型Agent开发(CrewAI)
大数据·人工智能·python·机器学习·ai
aqi0044 分钟前
鸿蒙版本的小小机器人APP开放源码啦
人工智能·华为·harmonyos·鸿蒙·harmony
眼泪划过的星空1 小时前
快速了解LangGraph:构建智能Agent工作流的核心框架
人工智能·python·langchain
lmy_loveF1 小时前
华为模拟器添加卡片
华为·鸿蒙
IsSh9nj6q2 小时前
Python全栈应用搭建神器magic-dash .新版本介绍
开发语言·python·dash
Cachel wood2 小时前
hands-on-modern-rl:动手学强化学习策略梯度reinforce
开发语言·python
qizayaoshuap2 小时前
鸿蒙 ArkTS 实战:搜索列表 城市实时过滤(示例 94)
android·华为·harmonyos