Debug it

Find and fix common errors in your code
Logic errors in Python: Find and fix common errors in your code

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

  1. 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.

  2. 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

  3. 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.