Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: http://docs.python.org/tutorial/floatingpoint.html

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?

like image 816
orange Avatar asked Dec 13 '10 19:12

orange


1 Answers

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."
else:
    print "Good luck. Python is fun."

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

like image 131
Pablo Avatar answered Oct 14 '22 15:10

Pablo