我想要一个错误检查以确保字符串有元音输入
i would like an error check to ensure that the string has vowels input
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]))
我希望我的代码在此基础上输出出现次数最少的元音我想要错误检查以确保字符串中输入了元音
您的示例中存在很多格式和语法问题,但以下内容有效并且与您尝试的方式相当接近:
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]))
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]))
我希望我的代码在此基础上输出出现次数最少的元音我想要错误检查以确保字符串中输入了元音
您的示例中存在很多格式和语法问题,但以下内容有效并且与您尝试的方式相当接近:
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]))