Homework 1
Practical programming skills in Python
Homework 1 Fundamentals
1. Debugging
Look at the following code – there are 3 errors.
weightOne = float(input(“Enter the weight of box 1: ”))
weightTwo = float(input(“Enter the weight of box 2: ”))
if weightOne > weightTwo:
print(“Box 1 is lighter”)
elif weightOne < weightTwo:
Print(“Box 2 is lighter”)
else:
print(“The two boxes weigh the same)
Identify each error, state whether it is a logic or syntax error and explain how to fix it. [6]
Error 1:
Type of error:
Solution:
Error 2:
Type of error:
Solution:
Error 3:
Type of error:
Solution:
2. Runtime error
Give an example of a value the user could enter that would trigger a runtime error. [2]
1
Homework 1
Practical programming skills in Python
3. Print Statements
Describe the output of the following program. [2]
name = “Dave”
age = 23
topping = “mushroom”
print(name + “is” , age , “years old.”)
print(name , “ loves ” + topping + “ pizza.”)
Rewrite the last two lines of code so that the printout is neat and tidy. [2]
4. Data Types
Re-write the following table to match the data types with their descriptions and examples:
Data Type Description Example
integer Any piece of text True
float Can only be True or False 5
boolean A fractional number “Dave”
string A whole number 7.3
Data Type Description Example
Integer
float
boolean
string
[4]
[Total 16 marks]
2