GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Count vowels in python using function - w3resource

Python: Count vowels in python using function

Last update on May 17 2025 05:43:58 (UTC/GMT +8 hours)


Vowel Tester

Write a Python program to test whether a passed letter is a vowel or not.

Pictorial Presentation:

Test whether a passed letter is a vowel or not


Sample Solution:

Python Code:

# Define a function called is_vowel that takes one parameter: char (a character).
def is_vowel(char):
    # Define a string called all_vowels containing all lowercase vowel characters.
    all_vowels = 'aeiou'

    # Check if the input character (char) is present in the all_vowels string.
    return char in all_vowels

# Call the is_vowel function with two different characters and print the results.
print(is_vowel('c'))  # Output: False (character 'c' is not a vowel)
print(is_vowel('e'))  # Output: True (character 'e' is a vowel)

Sample Output:

False                                                                                                         
True 

Explanation:

The said code defines a function called "is_vowel" which takes in one parameter "char". First, the function declares a variable "all_vowels" containing all lowercase vowels. The function then uses the "in" operator to check whether the value of "char" parameter is present within the "all_vowels" string, and returns the result.

In the last two lines the code call the function "is_vowel" twice, with the input values 'c' and 'e' and print the results.

In the first case, False will be returned, while in the second case, True will be returned.

Flowchart:

Flowchart: n (non-negative integer) copies of the first 2 characters of a given string.


For more Practice: Solve these Related Problems:

  • Write a Python program to check if a string contains at least one vowel.
  • Write a script that counts the number of vowels in a given string.
  • Write a function that removes all vowels from a given string.
  • Write a program that finds the longest consecutive sequence of vowels in a string.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to get the n (non-negative integer) copies of the first 2 characters of a given string. Return the n copies of the whole string if the length is less than 2.
Next: Write a Python program to check whether a specified value is contained in a group of values.

Python Code Editor:

 

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.