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

相关推荐
love530love4 小时前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
cui_ruicheng6 小时前
Python从入门到实战(十六):多进程编程
开发语言·python
不言鹅喻7 小时前
HarmonyOS ArkTS 实战:实现一个校园考试安排与考场查询应用
华为·harmonyos
humors2217 小时前
新手笔记本/路由/手机安全问题小记
安全·华为·电脑·手机·路由器·笔记本·tplink
_Jimmy_8 小时前
FastAPI + SQLAlchemy全局事务管理
python·fastapi
用户8356290780518 小时前
如何使用 Python 在 Excel 中添加、编辑和删除超链接
后端·python
FF2501_9402285810 小时前
HarmonyOS开发实战:小分享-App项目架构全景解析
后端·华为·harmonyos·鸿蒙
AC赳赳老秦10 小时前
企业工商公开信息采集分析:OpenClaw 批量查询企业工商信息,生成企业画像报告
大数据·开发语言·python·自动化·php·deepseek·openclaw
解局易否结局10 小时前
鸿蒙原生开发实战:Native 图片处理与二维码全链路解析
华为·harmonyos
FoldWinCard10 小时前
D6 Python 基础语法 --- 保留关键字
开发语言·python