2016-11-15 68 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]))