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

相关推荐
xurileidian19 分钟前
第 24 篇 · 边玩边学Python · while 与死循环怎么退
服务器·前端·python
有个傻瓜32 分钟前
工具调用参数每次都差一截:finish_reason=length 输出预算截断的排错复盘与四种分诊实测
python·故障排查·ai agent·大模型应用开发·function calling
zhanghongyi_cpp1 小时前
第5章 学习自测
python·学习
程序猿追2 小时前
HarmonyOS 7 ArkUI 四则计算器:优先级、括号与除零修正
华为·harmonyos
打工仔折腾 AI2 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
IvanCodes3 小时前
LangChain(15):LangSmith 应用评估与回归测试
python·langchain·agent
炸薯条!4 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
leon_teacher4 小时前
HarmonyOS 7 Health Service Kit 实战:打通手表健康数据授权
华为·harmonyos
NJPJI_Yang5 小时前
鸿蒙操作系统使用 Gesture 实现手势识别与冲突处理实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
jason_renyu5 小时前
Playwright 入门与实操:从安装、定位、断言到自动发博客,把浏览器自动化讲明白
运维·python·自动化·前端开发·浏览器自动化·playwright·e2e测试