In a modify task you take code that already works and adapt it so that it does something else.
This exercise comes with two text files. singers.txt is the file of eleven names from the predict task, and bands.txt holds six bands:
Nirvana
Blondie
Queen
The Carpenters
The Beatles
Rush
The editor starts you off with a program that always prints the bands file:
my_file = open("bands.txt", "r")
for line in my_file:
print(line)
my_file.close()
Adapt the code so that:
.txt onto the end of it,So an answer of bands, Bands or BANDS opens bands.txt, and an answer of
singers, Singers or SINGERS opens singers.txt. The user will always type
one of those two words.
Leave the loop exactly as it is. Each line of the file is printed with its newline still on the end, so there is a blank line after every name, just as in the predict task.
The question comes first, worded exactly like this:
Do you want to open the bands or singers file?
Then every line of the chosen file, each followed by a blank line.
Input:
Bands
Output:
Do you want to open the bands or singers file?
Nirvana
Blondie
Queen
The Carpenters
The Beatles
Rush
Ask the question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The question is part of the output that is checked here, so its spelling,
capital letters and punctuation count.
To try your program before you submit it, use the To sandbox button at the bottom of the editor. The sandbox comes with both text files.
Make sure that you check for the following things:
.lower() has its brackets, and its result is stored or used straight away:
it does not change the variable it is used on.".txt" is joined on with a +, and it includes the full stop.open(...) without quotes
around it. With quotes, Python looks for a file with the variable’s name.FileNotFoundError means the name you built does not match a file. Print it
to see what it really is..close() are unchanged.