我写了一个小程序来帮助我做数学作业:
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
(%d
表示整数)。你知道吗有关详细信息,请参阅维基百科的^{} format strings 文章。你知道吗
使用
%f
而不是%d
(将数字舍入为整数)打印浮点:This这个问题很好地解释了这种差异。你知道吗
相关问题 更多 >
编程相关推荐