📅  最后修改于: 2023-12-03 15:25:56.211000             🧑  作者: Mango
This program is designed to accept a string that contains all vowels (a, e, i, o, u). The program will check if the string contains all vowels and return a message accordingly.
vowels = set('aeiou')
def contains_all_vowels(s):
s = s.lower()
for character in s:
if character in vowels:
vowels.remove(character)
if not vowels:
return True
return False
s = input("Enter a string: ")
if contains_all_vowels(s):
print("The string contains all vowels!")
else:
print("The string does not contain all vowels.")
The code above defines a function contains_all_vowels
that accepts a string s
as an argument. The function iterates through each character in the string and removes it from the set of vowels if it is a vowel. If the set of vowels is empty after iterating through the string, the function returns True
, otherwise it returns False
.
The code prompts the user to enter a string and checks if it contains all vowels using the contains_all_vowels
function. It then outputs a message to the user indicating whether the string contains all vowels or not.
In conclusion, this program can be useful for verifying whether a string contains all vowels or not. It uses a simple algorithm to check for the presence of each vowel in the string and returns a message accordingly.