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

相关推荐
天天爱吃肉821831 分钟前
【重磅发布:拿下新超仁达代理权 】
大数据·人工智能·python·功能测试·汽车
神王宝宝 王者小学36 分钟前
面向领域驱动架构的查询实现方式
前端·python·架构
ningmengjing_2 小时前
Redis 从入门到实战:Python操作全攻略
数据库·redis·python
️学习的小王2 小时前
智能文档助手:基于RAG的本地化文档问答系统实战指南
人工智能·python·机器学习
小雨青年2 小时前
【HarmonyOS 7 沉浸光感深度实战】 02 全局开关、MaterialState 与最小 Demo
华为·harmonyos
不瘦80斤不改名2 小时前
05-vibe-coding-向agentic-engineering演进
人工智能·笔记·python·prompt
笨鸟先飞,勤能补拙3 小时前
AI 安全的下一个 5 年:从 Agent 到 AGI 的攻防博弈
人工智能·python·安全·web安全·网络安全·github·agi
Logintern093 小时前
LangSmith如何根据id关系,在服务端把扁平列表重建为树形结构,用于页面渲染Trace视图
python