The function takes a filename and x (which is meant to return the first 2 or 4 vowels in filename). The code I have written returns vowels but I'm not exactly sure what it is returning. The code should pass a doctest. I'm still trying to figure it out but if anyone has any advice on what I am doing wrong it would be very much appreciated as I am still relatively new to python.
the contents of the filename is: ("I have a bunch of red roses")
def return_vowels(filename, x):
"""
>>> return_vowels("roses.txt", 2)
'Ia' #returns the first two vowels in the text
>>> return_vowels("roses.txt", 3)
'Iae'#returns the first three vowels in the text
"""
files = open(filename)
text_file = files.read()
consonants = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"#do not want consonants
s_with_vowels = ""
index = 0
while index < x:
for letter in read_files:
if letter not in consonants:
s_with_vowels += letter
return s_with_vowels
if __name__=="__main__":
import doctest
doctest.testmod(verbose=True)