Here are some course notes for getting started with Python. In this article, I’ll show some more 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).
This is suspiciously similar to the code in the previous post, however I’ve modified it, so instead of reading from a list, it reads from a “csv” file called quiz.csv.
“csv” stands for “comma-separated-values”, it loosely defines a file format where the fields are separated by commas, and can be enclosed in quotes. Sometimes the fields are not separated by quotes, sometimes they are. It can all get rather confusing, so rather than try and write the code to read CSV files ourselves, we just rely on a library to do it.
Below is the code, that you should copy and save into a file called “quiz.py”, and also a CSV file that you should save as “quiz.csv” in the same directory. Once you have both, you should be able to run the code with
What can you do to improve the code? If you tried the previous example, may I suggest copying and pasting some of your modifications from that?