Below is some code that has been deliberately broken so that you can fix it.
It’s supposed to store a list of someone’s favourite sports. It asks the user to guess which sport is top of the list and then says if they’ve guessed correctly.
- Debug the code so that it runs without any errors
Syntax errors prevent the code from running because you’ve broken the rules of the programming language.
Hint: Look for missing brackets and other missing characters
- There should be a list called sports containing 4 values
This is just to make sure you don’t fix all the errors by removing all the code!
Hint: Look at line 3
- Check if the user types in the first sport in the list
You shouldn’t have to add anything new here: it’s just checking that if you guess correctly the program says well done, but if you choose a sport in the list but that’s not your favourite it detects that too.
On the next page you’ll get some ideas for projects where you can try to avoid making logic errors
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.