orange orange - 1 year ago 116
Python Question

Floating Point in Python

I'm learning via Learn Python The Hard Way and I've come across:

Notice the math seems “wrong”? There are no fractions, only whole numbers. Find out why by researching
what a “floating point” number is.

I've read what it is on:

I can't figure out on how I can output floating point numbers, I've thought about using
round(3 + 3, 2)

Is this right?

Answer Source

For floating point numbers you write a period after the number, and a zero (if it's a whole number).

Like this:

1.0 <---- Floating point.

1 <------- integer

That is how python interprets them.

if my_answer != your_question:
    print "I did not understand your question. Please rephrase it."
    print "Good luck. Python is fun."

I agree with rohit, the 0 is not needed. Although it makes things easier for beginners.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download