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?

Make

What’s a ‘Make’ Task?

In these tasks you have to use the skills learned in the previous exercises to create a new program based on the requirements below.

  • Create two text files. One with at least 5 first names of people in your class, the other with at least 5 surnames. Give them suitable lower case names and upload them into the repl.

Write a program that:

  • Outputs the name of the two files to the user.
  • Asks them to choose a file to read. Store their choice.
  • Converts their choice to lower case and concatenate with ‘.txt’
  • Read and output the chosen file.

EXTRA CHALLENGE

  • Validate the user input so the program does not accept entries that don’t match the two file names.

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