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

相关推荐
隔壁小红馆39 分钟前
隐藏odoo特有
python·odoo17·odoo18
lifewange44 分钟前
pytest 找不到文件?直接在 pytest.ini 配置根目录 + 路径(最简单方案)
开发语言·python·pytest
yuanpan1 小时前
Python 桌面 GUI 入门开发:从 tkinter 窗口到简易记事本
开发语言·python
川石课堂软件测试1 小时前
软件测试|常见面试题整理
数据库·python·jmeter·mysql·appium·postman·prometheus
做个文艺程序员1 小时前
Multi-Agent 系统实战:用 Python + LangGraph 搭建多智能体协作工作流
python·多智能体·langgraph·multi-agent
bang冰冰1 小时前
Trae工具安装和使用教程(新手零基础入门,全程无坑)
java·人工智能·python
User_芊芊君子1 小时前
聊聊自由开发者常用的学习机会全解析
开发语言·人工智能·python
weixin_376593222 小时前
使用pyhon脚本方式将超链接保存到第一列以数字方式显示
python
byzh_rc3 小时前
[AI编程从入门到入土] 装饰器decorator
开发语言·python·ai编程
贫民窟的勇敢爷们3 小时前
Java 与 Python 如何选型与融合
java·开发语言·python