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

相关推荐
paeamecium31 分钟前
【PAT甲级真题】- Rational Sum (20)
数据结构·c++·python·算法·pat考试·pat
爱昏羔7 小时前
下篇:从检索到交互 — 物流RAG问答系统与WebUI全实现
python·langchain·agent
_Jimmy_7 小时前
Agent引用数据库知识过时的增量同步方案
人工智能·python·langchain
min(a,b)9 小时前
学习第 4 天:面向对象与异常处理
python·学习·学习方法
yangshicong10 小时前
第19章:AI安全防护与AI安全
人工智能·python·安全·prompt·ai编程
果汁华10 小时前
Function Calling 与 Python 实战完整指南
开发语言·网络·python
c_lb728811 小时前
2026年不同基础做量化,先找AI能参与的位置
人工智能·python
chenment12 小时前
ComfyUI 自定义节点开发:从零扩展你的图像生成工作流
python·stable diffusion
IT空门:门主13 小时前
Python 基础语法学习路线图
网络·python·学习
互联网中的一颗神经元13 小时前
小白python入门 - 25. SQL 与表设计入门
数据库·python·sql