Here are some course notes for getting started with Python. In this article, I’ll show some code to play with.
Here’s some code, written for Python 3 (if you try and run it using Python 2, it will cause an error because the “input” statement for Python 2 is called “raw_input” instead).
There are a couple of new things in the code. Firstly, we discussed lists previously, but this uses a list of lists. A list can have a number of objects. The “quiz” list in this case has a list of objects; each object being a list!
Secondly, the “input” command is new. This command takes an argument of what it should ask the user, and returns the answer the user gave.
Can you improve this code? Things to try:
- Add some new questions
ifto see if the user was correct
- Add a variable to keep score and use it to tell the user how well they did
- When checking answers, it should not matter if the user uses lower case or upper case letters. How could you code for this?