#πŸ”’ Why is this a float and not and integer? Line 19. In-depth explanation for a beginner needed :)

15 messages Β· Page 1 of 1 (latest)

bold aspen
#

Line 19

dreamy valeBOT
#

@bold aspen

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.

grim summit
#

Even if it was one float and an integer, it will stay a float

zinc helm
#

operations involving floats can also be slightly off due to precision issues, for example 0.3 + 0.3 + 0.3 + 0.1 is not exactly equal to 1.0

unreal gulch
still light
#

fraction.Fraction is just as precise and may be easier to reason with in some applications. πŸ™‚

unreal gulch
#

I forgot that existed, but yeah. Both decimals and floats can be represented losslessly as fractions but not vice versa.

barren crown
#

@bold aspen - for more detail, take a look at some content on number types . Here's the official doc version - https://python-basics-tutorial.readthedocs.io/en/latest/types/numbers/index.html

I've got a book called "Learning Python 5th edition" which does a great job of explaining the number types.

Python Basics

Python’s four number types are integers, floating point numbers, complex numbers and Boolean numbers:,, Type, Examples,,, Integers,-1, 42, 90000000,, Floats, 90000000.0,-0.005, 9e7,-5e-3,, Complex ...

unreal gulch
#

In my opinion they should make fractions built-in and call it something like num as the first choice that new python users use (and only use floats and ints) when necessary. Removes so much confusion over the accuracy of floats...

dreamy valeBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.