🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.assertEqual(0.1 + 0.2, 0.3)
  2. B.assertTrue(0.1 + 0.2 is 0.3)
  3. C.assertAlmostEqual(0.1 + 0.2, 0.3)
  4. 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 →