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

相关推荐
砚底藏山河4 分钟前
python量化实操:冷热分层存储
java·开发语言·python·金融
十五年专注C++开发6 分钟前
pybind11:一个跨C++和Python平台的编程库
开发语言·c++·python·pybind11
2501_9445255419 分钟前
开源鸿蒙平台 KMP_CMP 三方库「EitherNet」适配全流程
华为·开源·harmonyos
炘爚22 分钟前
数据结构算法总结
数据结构·python·算法
信誓旦旦的程序猿23 分钟前
【Python量化实战宝典 #18】MACD 金叉死叉手册:DIF、DEA、柱体全拆解(Python 可跑)
java·python·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口
Patrick在香港31 分钟前
一个加 1 的动作,把最大值变成了最小值
python·numpy·数据类型·整数溢出·数据精度
weixin_BYSJ19871 小时前
电竞先锋网站---附源码02032
java·vue.js·spring boot·python·django·tomcat·php
不脱发的程序猿1 小时前
红利ETF量化策略
人工智能·python·ai·程序员·量化交易·etf·策略回测
Apok'1 小时前
零基础学Python量化(1):研究大纲与流程
python·机器学习·金融·数据挖掘·数据分析
鬓戈1 小时前
llmproxy 系统开发目的和基本功能
人工智能·python