How to Accept a String That Starts with a Vowel in Python

In this tutorial, we’ll learn how to program "How to Accept a String That Starts with a Vowel in Python." The objective is to understand and implement an efficient method for identifying whether a string starts with a vowel and displaying it accordingly. This tutorial will guide you step by step through the process, ensuring a clear understanding of how to filter and display strings that begin with a vowel. So, let’s get started!

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. def vowel_checker(s):
  4.         pattern = '^[aeiouAEIOU].*'
  5.         if re.match(pattern, s):
  6.                 return "String Accepted!"
  7.         else:
  8.                 return "String Not Accepted!"
  9.  
  10. while True:
  11.         print("\n================= Accept a String That Starts with a Vowel =================\n\n")
  12.  
  13.         string = input("Enter a string: ")
  14.         print(vowel_checker(string))
  15.  
  16.         opt = input("\nDo you want to try again?(yes/no): ")
  17.  
  18.         if opt.lower() == 'yes':
  19.                 ret=False
  20.         elif opt.lower() == 'no':
  21.                 ret=True
  22.                 print("Exiting program....")
  23.         else:
  24.                 print("Please enter yes/no:")
  25.                 break
  26.  
  27.         if ret == False:
  28.                 continue
  29.        

This program checks whether a given string starts with a vowel (either uppercase or lowercase). It uses a regular expression to match strings that begin with any of the vowels (A, E, I, O, U). If the string starts with a vowel, it prints "String Accepted!"; otherwise, it prints "String Not Accepted!". The user can repeatedly enter strings until they choose to exit.

Output:

There you have it we successfully created How to Accept a String That Starts 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