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

相关推荐
Yu_Lijing几秒前
Python数据分析和数据处理库Pandas(Series篇)
人工智能·python·数据分析·pandas
九河_13 分钟前
从requirements.txt中安装缺失的包
python·conda·pip·环境管理
llm大模型算法工程师weng13 分钟前
Python爬虫实现指南:从入门到实战
开发语言·爬虫·python
AI效率工坊21 分钟前
【Python实战】10万行数据自动清洗:pandas+AI智能识别+异常检测完整方案
人工智能·python·pandas
乔江seven27 分钟前
LlamaIndex 实现ReAct Agent
前端·python·react.js
lifallen33 分钟前
一篇文章讲透 Flink State
大数据·数据库·python·flink
HMS Core42 分钟前
化繁为简:顺丰速运App如何通过 HarmonyOS SDK实现专业级空间测量
华为·harmonyos
郝学胜-神的一滴1 小时前
激活函数:神经网络的「非线性灵魂」,让模型从“直线”走向“万能”
人工智能·pytorch·python·深度学习·神经网络·程序人生·机器学习
雨墨✘1 小时前
PHP怎么执行Shell命令_exec与shell_exec区别说明【说明】
jvm·数据库·python
2201_756847331 小时前
mysql字段长度不够用了怎么办_使用alter table扩大varchar长度
jvm·数据库·python