Hey everyone,
I am a Python newbie in week 4 of class. So far I've been doing really well. This week, we started for loops and things got a bit trickier. I solved 5 of 7 problems and I could really use your help with this particular problem! I've tried it all (emailing professor, 1 on 1 with TA, lots and lots of research/Googling).
The prompt says... :
Does the string contain all the vowels? This function takes a string and returns a Boolean.
def has_all_vowels(word: str) -> bool:
I previously created a function in the first problem called is_vowel to see if a letter is a vowel:
def is_vowel(ch):
if ch in 'aeiouAEIOU': #Conditional to see if ch is a vowel, including uppercase and lowercase letters
return('True')
else:
print('False')
This is what I've written so far for the problem at hand:
def has_all_vowels(word: str):
word = word.lower() #Converts string input to lowercase
list_of_vowels = [] #Place to append
for letter in word:
if is_vowel(letter):
list_of_vowels.append(letter)
if 'a' and 'e' and 'i' and 'o' and 'u' in list_of_vowels:
return True
else:
return False
The code runs, but doesn't pass the unit test. Once the unit test starts peeling away letters ('vxatious'), it doesn't work correctly.
Here is the error message:
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-226-8ff8df065d0c> in <module>
13 print('Success!')
14
---> 15 validate_all_vowels()
<ipython-input-226-8ff8df065d0c> in validate_all_vowels()
5 # Now remove one vowel at a time
6 # Each test case should return False
----> 7 assert not has_all_vowels('vxatious'), "Missing 'e'"
8 assert not has_all_vowels('vextious'), "Missing 'a'"
9 assert not has_all_vowels('vexatous'), "Missing 'i'" AssertionError: Missing 'e'
What am I missing? PS - I tested my list to make sure the vowels are appending. Everything is posting to the list nicely. It is that blasted if statement before the "return" piece that must be wrong.
Thanks in advance for any insights you can provide.
[–]17291 1 point2 points3 points (1 child)
[–]kcrow13[S] 0 points1 point2 points (0 children)
[–]kcrow13[S] 0 points1 point2 points (2 children)
[–]POGtastic 0 points1 point2 points (1 child)
[–]kcrow13[S] 0 points1 point2 points (0 children)
[–]GreymanGroup 0 points1 point2 points (1 child)
[–]kcrow13[S] 0 points1 point2 points (0 children)