import math print "What is the radius of your circle?(Enter as x.xx)" radius = float(raw_input ("> ")) circumference = radius * 2.00 * math.pi print "The circumference of your circle is: %d" % circumference
2 Replies - 243 Views - Last Post: 22 March 2013 - 01:50 PM
I can't get a floating point number to calculate in a simple progr
Posted 22 March 2013 - 01:25 PM
I'm trying to learn Python on my own and I'm doing little projects to learn the nuances of the language. In the simple script below I'm trying to take a radius of a circle as input from a user and print out the circumference of the circle. It always rounds to a whole number though and I can't figure out why. Can someone give me some hints or point me in the right direction as to why? I'm not looking for full solutions here just a little direction.
Replies To: I can't get a floating point number to calculate in a simple progr
Re: I can't get a floating point number to calculate in a simple progr
Posted 22 March 2013 - 01:50 PM
%f (for floating point) works too. The format specifier %d is used to print integers and, as you noticed, it will convert anything that isn't an integer to an integer before printing it.
Page 1 of 1