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.
Page 1: Intro
Page 2: The theory: learn what you need to know as fast as possible.
Page 3: Try it: try out and adapt some working python code snippets.
Page 4: Debug it: Learn how to find and fix common mistakes.
Page 5: Extend it: Choose a project idea to use your newfound python skills.
Nice post! Thanks for sharing information.