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

相关推荐
只与明月听1 分钟前
FastAPI入门实战
前端·后端·python
无心水12 分钟前
【Python实战进阶】12、Python面向对象编程实战:从零构建搜索引擎,掌握封装、继承与多态!
开发语言·python·搜索引擎·python进阶·python面向对象·搜索引擎实战·封装继承多态
mortimer12 分钟前
Python + FFmpeg 视频自动化处理指南:从硬件加速到精确剪辑
python·ffmpeg·音视频开发
帅得不敢出门15 分钟前
Android8 Framework实现Ntp服务器多域名轮询同步时间
android·java·服务器·python·framework·github
haiyu_y28 分钟前
Day 29 异常处理
python
古城小栈29 分钟前
Python 3.14:重塑开发体验的五大技术突破与实践指南
开发语言·python
小糖学代码37 分钟前
LLM系列:1.python入门:1.初识python
服务器·开发语言·人工智能·python·ai
海边夕阳20061 小时前
【每天一个AI小知识】:什么是人脸识别?
人工智能·经验分享·python·算法·分类·人脸识别
Q_Q5110082851 小时前
python+django/flask医药垃圾分类管理系统
spring boot·python·django·flask·node.js·php