华为机考入门python3--(0)模拟题2-vowel元音字母翻译

分类:字符串

知识点:

  1. 字符串转list,每个字符成为list中的一个元素    list(string)

  2. 字符串变大小写    str.upper(), str.lower()

题目来自【华为招聘模拟考试】

图片



# 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 软件工程小施同学

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-22 06:34:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-22 06:34:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-22 06:34:04       87 阅读
  4. Python语言-面向对象

    2024-01-22 06:34:04       96 阅读

热门阅读

  1. Kubernetes(k8s)(一)

    2024-01-22 06:34:04       50 阅读
  2. Apache Wicket 9.10.0发布

    2024-01-22 06:34:04       63 阅读
  3. 网络安全产品之认识入侵防御系统

    2024-01-22 06:34:04       65 阅读
  4. ChatGPT与文心一言:谁更胜一筹?

    2024-01-22 06:34:04       53 阅读
  5. P8761 [蓝桥杯 2021 国 BC] 大写

    2024-01-22 06:34:04       40 阅读
  6. mini-spring-Bean含参实例化(三)

    2024-01-22 06:34:04       48 阅读