python - How to calculate and print the least and most occurring vowels in a string? -
i required input string, calculate number of vowels in string, , calculate , to the lowest degree occurring vowels. when string contains no vowels @ all, message should print saying "no vowels entered". there vowels occur same number of times (e.g. if , e both occur twice ), these vowels should both appear beingness or to the lowest degree occurring. however, if vowels in string not all, ones not appear in sting should ignored (rather printing "a=0"). think counting part @ start right extent, not quite. most/least occurrences, don't know begin. help appreciated!
mystring = str(input("please type sentence: ").lower()) count = [0, 0, 0, 0, 0] vowel in mystring: if vowel == "a" : count[0]=count[0]+1 if vowel == "e" : count[1]=count[1]+1 if vowel == "i" : count[2]=count[2]+1 if vowel == "o" : count[3]=count[3]+1 if vowel == "u" : count[4]=count[4]+1 while count[0] > 0: print ("acount :",count[0]) break while count[1] > 0: print ("ecount :",count[1]) break while count[2] > 0: print ("icount :",count[2]) break while count[3] > 0: print ("ocount :",count[3]) break while count[4] > 0: print ("ucount :",count[4]) break else: if count[0] == 0 , count[1] == 0 , count[2] == 0 , count[3] == 0 , count[4] == 0: print ("no vowels found")
from collections import counter d = counter(input("enter sentence:")) print sorted("aeiou",key=lambda x:d.get(x,0))
seems much easier way ...
python
No comments:
Post a Comment