본문 바로가기
프로그래밍 문제/[Python] CheckIO

[CheckIO] Count Vowels

by Physics 2024. 2. 18.
728x90

1. Problem: https://py.checkio.org/en/mission/count-vowels/   
2. My solutions

def count_vowels(text: str) -> int:
    # your code here
    number_vowels = 0
    lower_case = text.lower()
    for vowel in ['a','e','o','i', 'u']:
        number_vowels += [*lower_case].count(vowel)
    
    print(number_vowels)
    return number_vowels


print("Example:")
#print(count_vowels("Hello"))

# These "asserts" are used for self-checking
assert count_vowels("hello") == 2
assert count_vowels("openai") == 4
assert count_vowels("typescript") == 2
assert count_vowels("a") == 1
assert count_vowels("b") == 0
assert count_vowels("aeiou") == 5
assert count_vowels("AEIOU") == 5
assert count_vowels("The quick brown fox") == 5
assert count_vowels("Jumps over the lazy dog") == 6
assert count_vowels("") == 0

print("The mission is done! Click 'Check Solution' to earn rewards!")

 

728x90

댓글