Idle considered this colon(if len(words)==2 and a>b:) as invalid syntax. Can you help me out?
def num_vowels(s):
""" returns the number of vowels in the string s
input: s is a string of 0 or more lowercase letters
"""
if s == '':
return 0
else:
num_in_rest = num_vowels(s[1:])
if s[0] in 'aeiou':
return 1 + num_in_rest
else:
return 0 + num_in_rest
def most_consonants(words):
a=(len(words[0]) - num_vowels(words[0]))
b=(len((words[1]) - num_vowels(words[1]))
if len(words)==2 and a>b:
return words[0]
elif len(words)==2 and a<b:
return words[1]
elif (len(words[0]) - num_vowels(words[0])) < (len((words[1]) - num_vowels(words[1])) :
return most_consonants(words[1:])
elif (len(words[0]) - num_vowels(words[0])) > (len((words[1]) - num_vowels(words[1])) :
return most_consonants([word [0]]+words[2:])
Aucun commentaire:
Enregistrer un commentaire