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

相关推荐
2301_77514815几秒前
CSS如何实现固定头部布局_利用position-fixed实现顶部常驻
jvm·数据库·python
yejqvow122 分钟前
Python测试中如何控制顺序_使用pytest-ordering自定义执行流
jvm·数据库·python
栗少3 分钟前
Python 入门教程(面向有 Java 经验的开发者)
java·开发语言·python
峥嵘life4 分钟前
Android 切换用户后无法获取 MAC 地址分析解决
android·python·macos
m0_613856297 分钟前
mysql如何使用IF函数_mysql简单二元逻辑转换
jvm·数据库·python
爱喝热水的呀哈喽8 分钟前
5步创建一个有不同numpy scipy版本的python环境
python·numpy·scipy
pele14 分钟前
如何在 Go 项目中安全、高效地共享 MySQL 数据库连接
jvm·数据库·python
qq_3422958218 分钟前
SQL如何用SQL子查询查找最大值对应行_关联主键优化方案
jvm·数据库·python
m0_7436239218 分钟前
golang如何使用iota常量生成器_golang iota常量生成器使用教程
jvm·数据库·python