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

相关推荐
Swift社区4 分钟前
鸿蒙 App 为什么需要统一状态源?
华为·harmonyos
旅僧10 分钟前
运行UMI镜像
python
星释12 分钟前
HDC 2026 跨平台框架专题:HarmonyOS 生态下的跨端技术全景
华为·harmonyos
ellenwan202612 分钟前
期货跨期价差程序化怎么做:天勤 SP 合约与腿比例核对
python·区块链
月疯14 分钟前
torch:expand和repeate的区别
开发语言·python·深度学习
顾林海34 分钟前
Agent入门阶段-编程基础-Python:Python 开发环境与运行方式
python·agent·ai编程
加农炮手Jinx35 分钟前
Flutter for OpenHarmony:pub_updater 命令行工具自动更新专家(DevOps 运维必备) 深度解析与鸿蒙适配指南
android·运维·网络·flutter·华为·harmonyos·devops
叫我:松哥36 分钟前
基于深度卷积神经网络的水果图片分类算法设计与实现,有ResNet50的迁移学习模型,准确率达95%
人工智能·python·神经网络·机器学习·分类·cnn·迁移学习
Orchestrator_me1 小时前
Python pip install报SSL错误
python·ssl·pip
开源量化GO1 小时前
期货 K 线算信号 tick 级止损:天勤双序列 wait_update 触发规则
linux·运维·服务器·python