#๐ why is the sum not 10.3
15 messages ยท Page 1 of 1 (latest)
@stuck plover
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.
did you mean 20.3 in the title?
yes
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)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
0.30000000000000004
thanks.
Wait wat ๐ณ
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
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
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.