0

Just have started learning how to code on python. And I wrote a simple program with calcutation, then I've encountered a bug (well I'm not sure if I should call it a bug). Please, explain me what went wrong, and why did I get such a strange result, and how to fix it?

here is the code

[num1 = input('Enter a number: ')
num2 = input('Enter another number: ')
result = float(num1) + float(num2)

print(result)][1]

input 1st = 2.2 input 2nd = 1.1 result : 3.3000000000000003

1 Answers1

0

To settle your issue you can use round() in the first parameter give the float number and the second parameter the number you would take after the dot.

num1 = input('Enter a number: ')
num2 = input('Enter another number: ')
result = float(num1) + float(num2)

print(round(result, 2)) #round(0.123456, 2)
amd
  • 342
  • 1
  • 2
  • 15