# Extending the Quiz

This task involves extending your quiz on farming so that it has the following functions:

• The questions are stored in a text file, together with the answer
• The user is asked one question at a time
• The user is told if they are right or wrong then the next question is presented.
• The user's score is given at the end of the quiz

Some questions have been saved for you in the file farming.csv, which you can download.

The questions have been saved in a text file in a csv (comma-separated values) format.

Here is an extract from the file

Use a module called csv to read in from the file. Here is the code to start you off...

 1 2 3 4 5 6 7 8 9 import csv def get_questions(): questions = [] with open("farming.csv", mode="r", encoding="utf-8") as my_file: reader = csv.reader(my_file) for row in reader: questions.append(row) return questions 

## Extension

There are many extensions that could be built into this quiz. For example,

• The user is asked how many questions they want to answer
• The questions are presented randomly

Choose an extension and improve the quiz program!

by Sue Sentance.
20 June 2011.
updated on 03 September 2014.

Find the solutions to these exercises on GitHub.