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

相关推荐
BigBookX18 分钟前
使用OpenCV来获取视频的帧率
python·opencv
蹦蹦跳跳真可爱58920 分钟前
Python----计算机视觉处理(opencv:像素,RGB颜色,图像的存储,opencv安装,代码展示)
人工智能·python·opencv·计算机视觉
不会写代码的码农农23 分钟前
【2025年26期免费获取股票数据API接口】实例演示五种主流语言获取股票行情api接口之沪深A股涨停股池数据获取实例演示及接口API说明文档
java·开发语言·python·股票api·股票数据接口·股票数据
BIT_Legend39 分钟前
Torch 模型 model => .onnx => .trt 及利用 TensorTR 在 C++ 下的模型部署教程
c++·人工智能·python·深度学习
蹦蹦跳跳真可爱5891 小时前
Python----计算机视觉处理(Opencv:自适应二值化,取均值,加权求和(高斯定理))
人工智能·python·opencv·计算机视觉
dreadp1 小时前
使用 OpenSSL 和 Python 实现 AES-256-CBC 加密与解密(安全密钥管理)
python·安全·网络安全·密码学·openssl
IT北辰2 小时前
《用 python、MySQL 和 Chart.js 打造炫酷数据看板》实战案例笔记
python
weixin_307779132 小时前
PyTorch调试与错误定位技术
开发语言·人工智能·pytorch·python·深度学习
魔障阿Q2 小时前
Yolo-Uniow开集目标检测本地复现
人工智能·python·yolo·目标检测·计算机视觉
用户9704438781162 小时前
如何在自己的网站接入API接口获取数据
人工智能·python·开源