#๐Ÿ”’ why is the sum not 10.3

15 messages ยท Page 1 of 1 (latest)

dim saddleBOT
#

@stuck plover

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rapid heart
#

did you mean 20.3 in the title?

stuck plover
#

yes

rapid heart
#

the reason is due to how computers represent numbers; some decimal numbers can only be approximated if you only have a finite number of digits

#

so when you add 2 of those together, the errors add up to form what you see

#

!e a popular example is

print(0.1 + 0.2)
dim saddleBOT
golden rampart
stuck plover
#

thanks.

unkempt island
#

Wait wat ๐Ÿ˜ณ

rustic rain
#

You can fix this py doing

print("Addition Calculator")

a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))

print(round(a + b, 1))
#

welcome

stuck plover
#

Deleted the screenshot coz it was showing some personal info, thanks for all the help
Now I understand that computers cannot convert certain things to binary accurately

dim saddleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.