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

相关推荐
一只旭宝7 分钟前
预约系统版本2(pyhton+flask可视化版本)
服务器·数据库·c++·笔记·python·flask
小飞学编程...22 分钟前
【equals 、Comparable、Comparator 三者的区别】
java·python
青 春 记 忆29 分钟前
零基础入门python21:Flask账本的数据模型——用户、分类和账目
python·flask·后端开发
hy.z_77735 分钟前
【软件测试】8. 自动化测试实践
python
楠楠子呀1 小时前
从零构建高性能 WhatsApp 链接生成器与重定向服务:架构与路由解析
redis·python·容器·架构·flink·散列表·flume
OPEN-F1 小时前
Python进阶教程:算法与数据结构入门
开发语言·python
薛定猫AI1 小时前
【技术干货】Claude Code多模型代理与反馈闭环:Python实现可验证的AI编程工作流
开发语言·python·ai编程
每天一道题1 小时前
从 async/await 到幂等恢复:把 Python 并发和 Agent Runtime 一次讲清楚
分布式·python
一只积极向上的小咸鱼1 小时前
pytorch 与资源核算
人工智能·pytorch·python