Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1'5' + 3 | AThe integer 16 is added to strings without conversion, causing a TypeError. It should be str(16) or the number should be written as '16'. | |
| 2int('5') + 3 | BRaises a TypeError because a string cannot be added to an integer | |
| 3input() always returns a string, so convert it with int() before doing maths | Cinput() returns a string, so multiplying it by a float causes a TypeError. It needs float(input('Qty: ')) or int(input('Qty: ')). | |
| 4To join a number to text, convert the number to a string with str() | DConverts the string to an integer first, so the answer is 8 | |
| 5total = input('Qty: ') * 2.5 | Eprint('Score: ' + str(10)) | |
| 6print('You are ' + 16 + ' years old') | Fage = int(input('Age: ')) + 1 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
TypeError — A runtime error when an operation gets the wrong data types, like '5' + 3 (string plus integer). Fix it by converting with int() or str(), e.g. int(input()).total = int(input("Enter a number: ")) + 5print("Score: " + str(score))try:
total = '5' + 3
except TypeError:num = int(input("Enter a number: "))age = input("Age: ")
print(type(age))