1

How can I print the following lines of code but get a floating point number of of it instead of a rounded int?

print "Math Question: ", 100 - 25 * 3 % 4

print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6

0

3 Answers 3

3

Division with / in 2.x results in a integer if both operands are integers. Either cast one of the operands to a float first, or from __future__ import division.

Sign up to request clarification or add additional context in comments.

Comments

3
from __future__ import divison

or run Python with the -Qnew option

Python3 has this behaviour by default

Comments

1

If you use integers, Python assumes you really mean them to be integers and does integer math. If you use floats, it will do floating point math.

Try something like this to get floating point output:

print 3/4.0

1 Comment

Not in 3.x, not with from __future__ import division, and not with -Qnew.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.