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

相关推荐
清水白石008几秒前
构建企业级 Python 服务:配置、日志、指标与追踪的稳健之道
开发语言·python·elasticsearch
happymaker062622 分钟前
SpringBoot使用Thymeleaf模板引擎,前端的基本语法
开发语言·python
程序猿追25 分钟前
在 HarmonyOS 屏幕上种一棵勾股定理长成的树——毕达哥拉斯分形绘制
华为·harmonyos
fengchengwu201230 分钟前
Conda 虚拟环境操作手册:从入门到精通
python·conda
deepin_sir32 分钟前
11 - 模块与包
前端·数据库·python
铁皮哥43 分钟前
【agent 开发】Claude Code 的 Skill 是怎么被加载的?从 name/description 到 SKILL.md 再到资源文件
java·服务器·数据库·python·gitee·github·软件工程
py小王子1 小时前
期刊复现|Python 实现带误差棒与3D 柱状数据可视化
python·期刊复现
财经资讯数据_灵砚智能1 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月25日
大数据·人工智能·python·信息可视化·自然语言处理·ai编程
是你就无限6151 小时前
FastAPI 核心技术与实战
python·fastapi