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

相关推荐
myzzb18 分钟前
纯python 最快png转换RGB截图方案 ——deepseek
开发语言·python·学习·开源·开发
宸迪24 分钟前
【python】使用uv管理项目包依赖
linux·python·uv
qq_4480111629 分钟前
python中的内置globals()详解
开发语言·python
weixin_4404016941 分钟前
Coze-智能体Agent(工作流:自定义插件+选择器+知识库检索+大模型润色)
python·ai·coze
Ulyanov1 小时前
基于Python的单脉冲雷达导引头回波生成技术
python·算法·仿真·单脉冲雷达、
deepxuan1 小时前
Day2--python三大库-numpy
开发语言·python·numpy
徐同保1 小时前
python如何手动抛出异常
java·前端·python
Dxy12393102163 小时前
Python检查JSON格式错误的多种方法
前端·python·json
Lightning-py3 小时前
ASCII,十进制,十六进制,八进制和二进制转换表
python
laplace01234 小时前
deque+yield+next语法
人工智能·笔记·python·agent·rag