October 13, 2024

Python Program for Accepting Strings that Contain All Vowels

To determine if a string contains all the vowels (a, e, i, o, u), you can create a Python program that checks if all these vowels are present in the given string. Here is a simple program that accomplishes this:

1. Python Program

# Function to check if a string contains all vowels
def contains_all_vowels(s):
    # Define a set of all vowels
    vowels = set('aeiou')
    
    # Convert the string to lowercase and create a set of characters in the string
    s_set = set(s.lower())
    
    # Check if all vowels are present in the string
    return vowels.issubset(s_set)

# Get user input
user_input = input("Enter a string: ")

# Check if the string contains all vowels and display the result
if contains_all_vowels(user_input):
    print("The string contains all vowels.")
else:
    print("The string does not contain all vowels.")

In this program:

  • The contains_all_vowels() function checks if all the vowels are present in the input string.
  • vowels = set('aeiou') creates a set of all vowels.
  • s_set = set(s.lower()) converts the input string to lowercase and then creates a set of characters.
  • vowels.issubset(s_set) checks if all vowels are present in the set of characters from the input string.
  • The program prompts the user for input and then uses the function to determine if the string contains all vowels, displaying the result accordingly.

2. Example Execution

Here is an example of how the program might work:

Enter a string: education
The string contains all vowels.

In this example, the input string “education” contains all the vowels (a, e, i, o, u), so the program outputs that the string contains all vowels.