2016-11-15 66 views
-1
from collections import Counter 
Astring = input("Enter a word or sentence: ") 
vowel = 'a' 'e' 'i' 'o' 'u' 
Astring = Counter(c for c in Astring.lower() if c in vowel) 
min_values = {mainv: Astring[mainv] for mainv in Astring if Astring[mainv] == min(Astring.values())} 

if vowel not in Astring: 
    print ("your text must contain vowels") 

else: 


    print("The least occuring vowel is:") 
    for m in min_values: 
     print("{vowel} with {occ} occurences.".format(vowel=m, occ=min_values[m])) 

我希望我的代码输出在此之上的最低发生元音我想一个错误检查,以确保该字符串在元音输入它我想一个错误检查,以确保该字符串有元音输入

+0

你有什么问题? –

+0

我想要进行错误检查以确保输入确实包含元音 – MasankoX25

+0

这不是问题,而是目标。 –

回答

0

很多的问题,在您例如格式和语法,但下面的作品和合理地接近你如何正试图做到这一点:

from collections import Counter 

VOWELS = ('a', 'e', 'i', 'o', 'u') 

string = raw_input("Enter a word or sentence: ") 
if not any(True for vowel in VOWELS if vowel in string.lower()): 
    print("your text must contain vowels") 
else: 
    print("The least occuring vowel is: {}".format(Counter(c for c in string.lower() if c in VOWELS).most_common()[-1]))