How to Accept String that Start with a Vowel in Python

In this tutorial, we will learn how to program "How to Accept a String that Starts with a Vowel in Python." We will check if the given string begins with a vowel. The objective is to safely and accurately validate if the entered string starts with a vowel. A sample program will be provided to demonstrate the coding process.

This topic is easy to understand. Just follow the instructions I provide, and you’ll be able to do it yourself with ease. The program I’ll show you demonstrates the correct way to validate if a string starts with a vowel. I’ll also provide a simple and efficient method to achieve this. So, let’s start coding!

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import re
  2.  
  3.  
  4. regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
  5.        
  6.  
  7. def check(string):
  8.  
  9.  
  10.         if(re.search(regex, string)):
  11.                 print("This string is Valid!")
  12.                
  13.         else:
  14.                 print("This string is not Invalid!")
  15.        
  16.  
  17.  
  18. if __name__ == '__main__' :
  19.  
  20.         while True:
  21.                 print("\n================= Accept String that Start with a Vowel =================\n\n")
  22.        
  23.                 string = input("Enter a string: ")
  24.        
  25.  
  26.                 check(string)
  27.  
  28.                 opt = input("\nDo you want to try again?(yes/no): ")
  29.  
  30.                 if opt.lower() == 'yes':
  31.                         ret=False
  32.                 elif opt.lower() == 'no':
  33.                         ret=True
  34.                         print("Exiting program....")
  35.  
  36.                 else:
  37.                         print("Please enter yes/no:")
  38.                         break
  39.  
  40.                 if ret == False:
  41.                         continue

This script checks if a given string starts with a vowel, followed by any combination of letters, numbers, or underscores. If the string meets these criteria, the program responds, "This string is Valid!" Otherwise, it responds, "This string is not Invalid!" The program then asks if the user wants to check another string, continuing until the user chooses to stop.

Output:

There you have it we successfully created How to Accept String that Start with a Vowel in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment