Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

I just don't know where to use int or float, so, when in doubt I use float. Am I right?

MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

int is for integer values when you know that you won't have decimal places. for example a counter for quantities that do need decimal precision (like money or distance) you should use float does that make sense?
"When in doubt, use float" has been exactly my strategy, though I do grasp the differences between them, as described by Chris.
You're pretty much right. Floats are basically scientific notation in binary. There are some values that they can't hit exactly. This can cause some interesting issues in comparison ( == ) statements.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

ints are standard and should be used when in doubt. They are 1, 2, 3, etc. Int ranges up to 2 million I believe. Floats also know as "Singles" as 32 bit decimal numbers 1.0, 2.4, 2.3242343242342343, etc. Double's are 64-bit floats.
If you are doing math operation it is good idea to use floats, but anywhere else it is better to use int.
float and int have a difference purposes. Float when you know for sure you will need it. For example lets say you have a variable you are going to use for a loop or comparision later in the program its better to use int and if needed a float value of that convert it.
Did you see lecture 2 video? Basically, BEWARE of using integers with division. With floats, 3.0 / 2.0 is 1.5. But 3/2 returns 1. As the lecturer pointed out, this is a trap for Python newbies because dividing one integer by another (like 3/2) is done with an integer result!
Remember that with Python 3.0 this dilemma is solved since it automatically uses float when a float could occur in the results. You can still override this by using e.g. `//` for integer (instead of float) division.
Int is an integer and float is a decimal. Right?

Not the answer you are looking for?

Search for more explanations.

Ask your own question