I've written a small program to help me with my math homework:
import math
def saCircle():
while True:
radius = float(raw_input("Enter the radius: "))
print "\nFinding area with %d as the radius" % radius
x = math.pi * radius**2
print "\nThe area of your circle is %d\n" % x
saCircle()
The problem is that it will accept a decimal number but it will not print out the value of the decimal number.
How can I fix this?
Use %f
instead of %d
(rounds your number to an integer) to print a float:
>>> radius = 4.4
>>> x = math.pi * radius**2
>>> print "\nThe area of your circle is %f\n" % x
The area of your circle is 60.821234
This question explains the difference very well.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments