Q. What will be the output of following Python code?

 

a = 12

b = 7.4

c = 1

a -= b

print(a, b)

a *= 2 + c

print(a)

b += a * c

print(b)


Answer :-

a = 12
b = 7.4
c = 1
a -= b # a = 12 - 7.4 = 4.6
print(a, b)
a *= 2 + c # a = 4.6 * ( 2 + 1 ) = 4.6 * 3 = 13.8 ~~ 13.799999999999999
print(a)
b += a * c # b = 7.4 + ( 13.799999999999999 * 1 ) = 7.4 + 13.799999999999999 = 21.2
print(b)

Output is:

4.6 7.4
13.799999999999999
21.2

 >>>


2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. how to get 13.79999999999

    ReplyDelete
    Replies
    1. Python does not support single precision floating point number.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post