1.

What is the result of sum([.1 for i in range(20)])?(a) 2.0(b) 20(c) 2(d) 2.0000000000000004The question was posed to me by my college professor while I was bunking the class.Question is taken from Math topic in chapter Mapping Functions and Modules of Python

Answer»

Right ANSWER is (d) 2.0000000000000004

Explanation: There is some LOSS of ACCURACY when we use sum with FLOATING point numbers. Hence the function fsum is preferable.



Discussion

No Comment Found

Related InterviewSolutions