14: Reading data from a file in python

Debug it

Use and store data in files
Reading data from a file in python

Below is some code that has been deliberately broken so that you can fix it. 

The code is supposed to ask you to type in a name. It will then check to see if that name matches the 100 most common baby names for boys or girls:

Example program output when the code h

Challenges

  1. Fix all syntax errors

    Hint: A syntax error means the code has broken the rules of the language. Work upwards from the line number in the error message to see what’s wrong or what’s missing.

  2. Make it so that it says Oliver is at position 1 rather than position 0

    Hint: According to the list in the CSV file, Oliver is the most popular name but i will be 0 for the first item in the list. You’ll have to add 1 to i when you display how popular the name is

  3. Fix the logic error so that it checks girls names too

    Hint: A logic error might not give you any error messages. At the moment the program should check the list of girls but it checks the list of boys twice. 

On the next page you’ll get some ideas for projects where you can use file output to create your own projects

Leave a Reply

Your email address will not be published. Required fields are marked *