10: Logic Errors in Python

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

2 thoughts on “10: Logic Errors in Python

  • February 26, 2019 at 10:33 am
    Permalink

    Shocking website!! I could not get the output without changing the browser which is not what a website should do!

    Reply
    • February 26, 2019 at 11:38 am
      Permalink

      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.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *