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

相关推荐
CodeCraft Studio1 小时前
国产化Excel开发组件Spire.XLS教程:Python将列表导出为CSV文件(含一维/二维/字典列表)
开发语言·python·excel·csv·spire.xls·列表导出为csv
Blossom.1181 小时前
大模型知识蒸馏实战:从Qwen-72B到Qwen-7B的压缩艺术
大数据·人工智能·python·深度学习·算法·机器学习·pygame
DIY机器人工房1 小时前
科普:华为星闪是什么?华为星闪(英文名 NearLink)是国际星闪无线短距通信联盟发布的新型无线短距通信标准技术。
stm32·嵌入式硬件·华为·嵌入式·diy机器人工房·嵌入式面试题
刘逸潇20051 小时前
Socket:TCP/UDP通信详解
python·websocket·udp·tcp
天黑请闭眼1 小时前
华为对象存储:nginx代理临时访问地址后访问报错:Authentication Failed
nginx·华为
The_Second_Coming2 小时前
Python 学习笔记:基础篇
运维·笔记·python·学习
诗句藏于尽头2 小时前
python实战学习记录
python·学习
AI松子6662 小时前
PyTorch-混合精度训练(amp)
人工智能·pytorch·python
MDLZH2 小时前
Pytorch性能调优简单总结
人工智能·pytorch·python
程序员爱钓鱼3 小时前
Python 编程实战 · 实用工具与库 — Flask 路由与模板
前端·后端·python