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

相关推荐
●VON3 小时前
鸿蒙 PC Markdown 编辑器内核:在 ArkWeb 中离线运行 CodeMirror 6
安全·华为·编辑器·harmonyos·鸿蒙
YM52e5 小时前
鸿蒙Flutter Padding内边距:EdgeInsets详解
android·学习·flutter·华为·harmonyos·鸿蒙
爱写代码的阿木6 小时前
基于鸿蒙OS开发附近社交游戏平台(二十二)-ChatPage 即时通讯 UI
游戏·华为·harmonyos
红烧大青虫7 小时前
HarmonyOS应用开发实战:小事记 - 数据迁移策略:RDB 表结构变更的版本号管理与 onUpgrade 回调
后端·华为·harmonyos·鸿蒙系统
qizayaoshuap8 小时前
# 温度转换 — HarmonyOS 双向转换器与表情符号天气描述实战
华为·harmonyos
郭老二8 小时前
【Python】基本语法:装饰器语法糖@
python
爱写代码的阿木9 小时前
基于鸿蒙OS开发附近社交游戏平台(二十三)-拉黑系统、屏蔽与全局过滤
游戏·华为·harmonyos
_Jimmy_9 小时前
Agent常用检索器的详细介绍
python·langchain
小柯南敲键盘10 小时前
图片翻译API接入与自动化实现指南
运维·python·自动化
旅僧10 小时前
Q-learning(自用)
python·机器学习