0

Idk why, but python think, that sum + boo = 1.3199999999999998.

My code:

def _percent(sum, do, percent):
  percent_1 = sum / 100
  boo = percent * percent_1
  print(f"Now boo = {boo}")
  if do == '+':
    return sum + boo
  elif do == '-':
    return sum - boo

print(f"Python think, that sum - boo = {_percent(1.20, '-', 10)}")
print(f"Python think, that sum + boo = {_percent(1.20, '+', 10)}")

Output:

/home/user-name/PycharmProjects/tupo-test/venv/bin/python /home/user-name/PycharmProjects/tupo-test/main.py
Now boo = 0.12
Python think, that sum - boo = 1.08
Now boo = 0.12
Python think, that sum + boo = 1.3199999999999998

Process finished with exit code 0

Python version:

Python 3.10.4

Luuk
  • 9,042
  • 4
  • 20
  • 28
ZZhjk
  • 1

0 Answers0