Debug it
Below is some code that has been deliberately broken so that you can fix it.
It’s supposed to ask you to to a bit of job research. It will ask you to enter the name of a job and the yearly salary you could earn if you get that job.
It should then calculate how much that yearly salary would mean you earn each month, year and day (before tax is taken off)
There’s one syntax error which prevents it from running and two logic errors where the code does what it’s told to do but doesn’t calculate the correct result.
Challenges
- Fix the syntax error on line 8
Syntax errors prevent the code from running because you’ve broken the rules of the programming language.
Hint: look at the brackets.
- The weekly salary is correct but is rounded to 4 decimal places instead of 2. Fix the logic error.
This challenge assumes that there are 52 weeks in the year which isn’t really true, but it’s close enough.
The salary should be rounded to 2 decimal places so you can see pounds and pence.
Hint: Look at lines 10-12
- The daily salary is incorrect. Find and fix the logic error
The code has got confused about how many days there are in a year. We’re ignoring leap years here, so you need to change it so that the yearly salary is divided by 365.
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.
Shocking website!! I could not get the output without changing the browser which is not what a website should do!
Shocking feedback!! Please could you let me know what browser you were using and what problem you had so I can improve the shocking website painstakingly put together for free in my spare time. It’s a long way from perfect. Alternatives are available.
Hiya, great website, the pound sign(£) creates a unicode error and the code will not run. If you delete the £’s it runs fine. I have tried this in Edge and Chrome.
Hello,
Thanks so much for getting in touch and reporting that bug. It should now be fixed – all strings should support unicode characters. Sorry about that!
All the best 🙂