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

相关推荐
风满城335 分钟前
鸿蒙原生应用实战(四):歌单管理 —— 创建歌单与歌曲编排
华为·harmonyos
Li#15 分钟前
AI编写操作使用说明书需要用到的工具和能力
python·ai编程·ai写作
红宝村村长24 分钟前
torch.autograd.Function.apply()
开发语言·python
花间相见26 分钟前
【LeetCode01】—— 无重复字符的最长子串:滑动窗口经典题详解
python·算法·leetcode
何以解忧,唯有..32 分钟前
Python 中的继承机制:从基础到高级用法详解
java·开发语言·python
金启攻1 小时前
鸿蒙原生应用实战(一):项目初始化与Stage模型架构设计
华为·harmonyos
try2find1 小时前
agent环境安装spacy
python·智能体
ellenwan20261 小时前
期货程序化开平标志错了总拒单:天勤 last_msg 排查思路
python
坚果派·白晓明1 小时前
鸿蒙PC】libuv适配:AtomCode Skills一站式指南
c语言·c++·华为·ai编程·harmonyos·atomcode
装不满的克莱因瓶1 小时前
自动微分的原理:计算图与前向传播
人工智能·pytorch·python·数学·ai·微积分·计算图