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

相关推荐
爱睡懒觉的焦糖玛奇朵5 小时前
【从视频到数据集:焦糖玛奇朵的魔法工具使用说明】
人工智能·python·深度学习·学习·算法·yolo·音视频
lqj_本人5 小时前
鸿蒙electron跨端框架PC今日打卡实战:频率、连续天数和今日进度怎么放进桌面工具
华为·harmonyos
yangshicong5 小时前
第11章:结构化输出与数据提取 —— 让 AI 直接返回你想要的数据格式
数据库·人工智能·redis·python·langchain·ai编程
言之。6 小时前
【Python】免费的中文 AI 配音方案
开发语言·人工智能·python
Warson_L6 小时前
python dict key详解
python
天天进步20156 小时前
Python全栈项目:从零手操一个高性能 API 网关
开发语言·python
安生生申7 小时前
使用pygame实现2048
开发语言·python·pygame
徐图图不糊涂8 小时前
搭建简易版的Rag系统
python·pycharm
灰灰勇闯IT8 小时前
pyasc:用 Python 调用 CANN 的推理能力
开发语言·python
明月_清风9 小时前
FastAPI 从入门到实战:3 分钟构建高性能异步 API
后端·python·fastapi