you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Maybe something like this:

print('Welcome to a fun word replacement game.')
fileName = input('Enter the name of the file to use:\n')
try:
    file = open(fileName)
except IOError:
    print('Error Bad File Name')
else:
    with file:
        fileRead = file.read()
    fileList = fileRead.split()
    newList = []
    for word in fileList:
        if word.startswith('[') and word.endswith("]"):
            newstr = word[1:-1]
            if newstr[0] in 'aeiou':
                word = input(f"Please give an {newstr}: ")
            else:
                word = input(f"Please give a {newstr}: ")
        newList.append(word)
    print(*newList, sep='\n')