← Quiz: Testing Python Code: all 10 questions
Quiz: Testing Python Code · Question 10 of 10
How should you compare two float results in a unittest test?
How should you compare two float results in a unittest test?
- A.assertEqual(0.1 + 0.2, 0.3)
- B.assertTrue(0.1 + 0.2 is 0.3)
- C.assertAlmostEqual(0.1 + 0.2, 0.3)
- D.Floats cannot be tested
Answer & explanation
Correct answer: assertAlmostEqual(0.1 + 0.2, 0.3)
Floating-point sums have tiny rounding errors, so an exact == check can fail.
Can you get the rest right without peeking?
Take the timed Quiz: Testing Python Code quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →