List Questions and Answers
First, we want to ask the user some questions, and provide them with the possible answers that will allow us to measure their carbon footprint.
- Open the starter project at bit.ly/mhcarboncalc
- On the left is your code window, on the right is the result of your code. You can click the “Run” button to run your code. You’ll notice that the first 2 lines have already been written for you.
- The first line tells us to use version 3 of Python, the second gets the data for our carbon calculator.
- Our data consists of a series of questions, with each of the answers given a value for how much carbon we’re using.
- Let’s start by listing out all the questions. To do this, we’ll write a ‘for’ loop that will give us each of the questions in turn.
- We want to write out each question. To do this, we’ll use the ‘print’ command.
- The questions are already in the data.py tab so we don’t need to write them out.
- Run your program using the ‘Run’ button. In your Result window, you should see a list of questions.
- For each question, we want to list out the answers. Add a second loop that outputs all the possible answers to the question.
- We want to number our answers to give the user something easy to type in. First, we need to set an initial value for our number.
- When programming we often use the letter ‘i’ to indicate
- Next, we need to increase the value of ‘i’ every time we go around our answer for loop.
- Now we can add this to the text of our answer.
- Run your program. You should now get all of the questions with numbered answers.