Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何让我的程序打印浮动?_Python_String_Math_Floating Point_Geometry - Fatal编程技术网

Python 如何让我的程序打印浮动?

Python 如何让我的程序打印浮动?,python,string,math,floating-point,geometry,Python,String,Math,Floating Point,Geometry,我写了一个小程序来帮助我做数学作业: 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

我写了一个小程序来帮助我做数学作业:

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() 
问题是它将接受十进制数,但不会打印出十进制数的值


如何解决此问题?

使用
%f
而不是
%d
(将数字四舍五入为整数)打印浮点:

>>> 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

问题很好地解释了差异。

浮点的格式说明符是
%f
,而不是
%d
%d
表示整数)


有关更多详细信息,请参阅上的维基百科文章。

谢谢。。。我会看看的。
print "\nFinding area with %f as the radius" % radius
                           ^