• We just launched and are currently in beta. Join us as we build and grow the community.

How to Accept String that Start with a Vowel in Python

Alan Blake

Giggle Programmer
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
178
Likes
121
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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. regex =

    '^[aeiouAEIOU][A-Za-z0-9_]*'


  3. def

    check(

    string

    )

    :


  4. if

    (

    re

    .search

    (

    regex,

    string

    )

    )

    :
  5. print

    (

    "This string is Valid!"

    )

  6. else

    :
  7. print

    (

    "This string is not Invalid!"

    )



  8. if

    __name__ ==

    '__main__'

    :

  9. while

    True

    :
  10. print

    (

    "\n

    ================= Accept String that Start with a Vowel =================\n

    \n

    "

    )

  11. string

    =

    input

    (

    "Enter a string: "

    )


  12. check(

    string

    )

  13. opt =

    input

    (

    "\n

    Do you want to try again?(yes/no): "

    )

  14. if

    opt.lower

    (

    )

    ==

    'yes'

    :
  15. ret=

    False
  16. elif

    opt.lower

    (

    )

    ==

    'no'

    :
  17. ret=

    True
  18. print

    (

    "Exiting program...."

    )

  19. else

    :
  20. print

    (

    "Please enter yes/no:"

    )
  21. break

  22. if

    ret ==

    False

    :
  23. 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:

how-to-accept-string-that-start-with-a-vowel-in-python-1.jpg

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


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,186

324,194

Top