replit

Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.

CoderSports

Read From A File

Need more help with file handling?

Modify

What’s a Modify task?

In the modify tasks, you are given some starter code. Use the instructions below to make changes to the code. Comment your changes to explain what you have done.

Task 1

Adapt the code so that:

  • It outputs the contents of the singers.txt file instead.

Task 2

Copy the code and adapt it so that:

  • It asks the user whether they want to open the bands or singers file.
  • Convert their input to lower case and concatenate it with .txt
  • It uses the input to open the chosen file and output the contents.

Help! My code doesn’t work

Make sure that you check for the following things:

  • Include the file extension (.txt) in the file name
  • Use the exact same file variable with open and in the loop.
  • Use exactly the same case in the filename.
  • Indenting all the code that should be inside loops.
  • Close the file once task is completed.

Hints