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

相关推荐
写代码的二次猿2 小时前
安装openfold(顺利解决版)
开发语言·python·深度学习
Eward-an2 小时前
LeetCode 1980 题通关指南|3种解法拆解“找唯一未出现二进制串”问题,附Python最优解实现
python·算法·leetcode
梦白.2 小时前
Python的容器类型
运维·python
木斯佳3 小时前
HarmonyOS 6实战:从爆款vlog探究鸿蒙智能体提取关键帧算法
算法·华为·harmonyos
天意__3 小时前
鸿蒙(ArkTS)与Flutter(Dart)开发语法全面对比
flutter·华为·harmonyos·arkts·dart·arkui
vistaup3 小时前
DevEco Studio 鸿蒙 HAR本地引入相互依赖问题解决
android·华为·harmonyos
@HNUSTer4 小时前
基于 Visual Studio Code 配置 Python 开发环境详细教程
ide·vscode·python·csdn开发云
tuotali20264 小时前
天然气压缩机技术2026,高可靠性长周期运行与智能运维融合路径
运维·python
fei_sun4 小时前
【鸿蒙智能硬件】(二)Windows开发环境
华为·harmonyos
Ama_tor4 小时前
Flask零基础进阶(中)
后端·python·flask