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

相关推荐
曾阿伦2 分钟前
Unicode 正则表达式开发指南
python·正则表达式
香辣西红柿炒蛋5 分钟前
yaml文件介绍、数据读取
python
李二。6 分钟前
鸿蒙原生ArkTS-太空探索新闻AI
人工智能·华为·harmonyos
乐于分享的阿乐6 分钟前
(二)VSCode搭建python环境(详细图文保姆级教程)
ide·vscode·python
weixin_4080996710 分钟前
2026 AI生成图片快速去水印的5种实测方法(附在线工具 + Python/Java/PHP API代码)
java·人工智能·python·api接口·ai去水印·石榴智能·自动去水印
2601_9611940214 分钟前
2026初级会计经济法基础知识点汇总
python·django·pdf·virtualenv·代理模式·pygame
爱就是恒久忍耐22 分钟前
Ubuntu解决pip3安装库提示This environment is externally managed的问题
linux·python·ubuntu
花落yu31 分钟前
AI学习:第2天
人工智能·python·学习
极光代码工作室31 分钟前
基于深度学习的文本自动摘要系统
人工智能·python·深度学习·神经网络
开源量化GO36 分钟前
期货量化订不到行情:天勤合约代码与交易所符号写法
python·区块链