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
Elizabeth visits her friend Andrew and then returns home by the same route. She always walks 2 kilometers per hour (km/h) when walking uphill, 4 km/h when walking downhill, and 3 km/h when walking on level ground. Suppose the path from Elizabeth's home to Andrew's home consists of 'y' meter in the level ground, 'x' meter in the uphill, 'z' meter in the downhill and Elizabeth starts from home by 6 a.m. Write an algorithm and the subsequent Python code to determine when Elizabeth will reach Andrew's home and when she will reach her home back if she spends 'm1' minutes in Andrew's home. For example, if y is 1000, 'x’ is 500, 'z' is 300 and m1 is '30' minutes, then Elizabeth takes 40 min to reach Andrew's home so she will reach Andrew's home by 6 hour 40 min. Elizabeth will take 37 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 47 min.
ReplyDeleteThe hour can be expressed in 12-hour format (not 24-hour format). The minutes elapsed should be rounded down to the nearest integer.