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 | |
|---|---|---|
| 1round(actual, 2) == expected | Around(0.1 + 0.2, 1) == 0.3 | |
| 20.1 + 0.2 == 0.3 | BComparing a float result directly with == gives False because 0.1 + 0.2 is 0.30000000000000004. Fix: print(round(0.1 + 0.2, 2) == 0.3) | |
| 3A test for a price calculation rounds the actual result to 2 decimal places (cents) before comparing it with the expected value | CEvaluates to False in Python because the float sum is really 0.30000000000000004 | |
| 4Choose the number of decimal places to match the precision of the expected value, such as 1 decimal place for an expected 0.3 | DThe expected value has more decimal places than the rounded result, so they never match and the test fails. Fix: round(actual, 2) == 0.33 | |
| 5print(0.1 + 0.2 == 0.3) | ERound the actual result to 2 decimal places, then compare it with the expected value to test a decimal result | |
| 6round(actual, 2) == 0.333333 | Fprint(round(price * 3, 2) == 7.5) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
round(actual, 2) == expected — Floats can be slightly inexact (0.1 + 0.2 is not 0.3), so round the actual result to a set number of decimal places before comparing it with the expected value.print(round(0.1 + 0.2, 2) == 0.3)actual = 0.1 + 0.2
print(round(actual, 2) == 0.3)actual = 0.1 + 0.2
print(round(actual, 2) == 0.3)expected = 0.3
if round(0.1 + 0.2, 2) == expected:
print("PASS")actual = 0.1 * 3
expected = 0.3
print(round(actual, 2) == expected)