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

相关推荐
青少儿编程课堂3 小时前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
Wellijohn3 小时前
Python 异常到底多贵?我把 try、raise、traceback 的账单逐项拆开测了一遍
后端·python·性能优化
Dmz丶4 小时前
前端转 AI 100 天 Day 55:RAG 项目实战(四)——前端完善,做一个能用的产品
python
geovindu5 小时前
python: KNeighborsClassifier K
开发语言·后端·python·算法
mattleeee5 小时前
Python脚本超时重试机制设计:失败立即重试,最多3次
python·超时·重试机制
笨鸟先飞的橘猫5 小时前
SLG 后端实战(一):基础建模与行军模拟
python·游戏程序
钉先生贾6 小时前
HarmonyOS API 26 ArkUI 性能定位:用帧预算拆解页面卡顿【鸿蒙心迹】
华为·harmonyos
Thanks_ks6 小时前
接口限流是怎么实现的:从固定窗口计数讲到滑动窗口日志
redis·python·限流·滑动窗口·漏桶·令牌桶·固定窗口
choicesages7 小时前
跑通不等于跑对:公开评论抓取里三处不报错的坐标问题
爬虫·python·数据清洗·数据质量·去重
鲸渔8 小时前
【AI Agent系列课程33-FastAPI 基础07】自动文档与接口调试:Swagger UI 和 ReDoc 入门
python·ui·fastapi·ai编程