Below is some code that has been deliberately broken so that you can fix it.
There aren’t any syntax errors or runtime errors but the code doesn’t do what the comments say it should do
- Fix the syntax error on line 7
In python you use one
=to set the value store in a variable.
If you want to test if two values are the same, you need to use
- At the moment Q2 only appears if you get Q1 wrong. Make it so Q2 always appears.
Indentation is really important in python. Any code that is indented under an if statement will only run if that condition is met.
- Find and fix the logical error
There’s actually two logical errors on the same line.
A logical error means that your code does what you’ve told it to do, but you’ve told it to do the wrong thing.
Here, our code compares the string value stored in
answerto Q2 with the integer value
40. That’s not right.
Think what value and data type
answershould be compared to instead.
On the next page you’ll get some ideas for extended projects to apply what you’ve learnt.