design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.

use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs

## LO: To debug simple programs.

Let's look at a program that needs debugging:

```#Terry's parcel weighs half a kilogram.
#Graham's weighs 300g.
#How much do they weigh together?

#declare variables for the key information
terry = 500g
graham = 300g

#define a function requiring two arguments
def add_weights(weight1, weight2): #seperate the arguments with a comma
print(weight1 + weight2)
return (weight1 + weight2) #remember to return a value, don't forget that space!

#call the function inputting the two variables as arguments

```

The first thing we should try to do is run the program in IDLE (but remember not all bugs are caused by typing mistakes - sometimes the program will run but give out incorrect or unexpected answers). Here we will get a syntax error that is caused when we have declared the variables terry = 500g and graham = 300g. If we remember back to 4.4a when we looked at variables we can see that 500g and 300g are not numbers so IDLE does not understand them.

```#Terry's parcel weighs half a kilogram.
#Graham's weighs 300g.
#How much do they weigh together?

#declare variables for the key information
terry = 500
graham = 300

#define a function requiring two arguments
def add_weights(weight1, weight2): #seperate the arguments with a comma
print(weight1 + weight2)
return (weight1 + weight2) #remember to return a value, don't forget that space!

#call the function inputting the two variables as arguments