Practice Problem 6-Vowelgram
Practice Problem 6-Vowelgram
Q.Vowelgrams are words or sentences that has every vowel (a,e,i,o,u) of the English alphabet occurring at the most once. Write an algorithm and a subsequent Python code to check whether a string is a vowelgram or not. Write a function to check if a given string is a vowelgram. For example,”You black tiger" is a vowelgram.
Input format
First line contains the string to be checked
Output Format
Print Vowelgram or Not vowelgram
Input:
the string
Processing:
def vowelgram(string):
count_a = string.count('a')
count_e = string.count('e')
count_i = string.count('i')
count_o = string.count('o')
count_u = string.count('u')
if count_a in (0,1)and count_e in (0,1) and count_i in (0,1) and count_o in (0,1) and count_u in (0,1):
return True
else:
return False
Output:
Display whether word is a vowelgram or not
Program:
def vowelgram(string):
count_a = string.count('a')
count_e = string.count('e')
count_i = string.count('i')
count_o = string.count('o')
count_u = string.count('u')
if count_a in (0,1)and count_e in (0,1) and count_i in (0,1) and count_o in (0,1) and count_u in (0,1):
return True
else:
return False
string = input().rstrip()
if vowelgram(string):
print('Vowelgram')
else:
print('Not vowelgram')
Algorithm:
Step1. Define the function vowelgram which takes one parameter that is the string and the definition goes as follows
Step1.1. count the number of ‘a’,’e’,’i’,’o’,’u’ in the string given
Step1.2. check whether the number of vowels of each kind is one or zero if true then return True else return False
Step2. Get the string
Step3. Call the function vowelgram and let string be the parameter and check whether it return True if it does then display Vowelgram else display Not vowelgram.
Step4. End
Comments
Post a Comment