我的代码显示3个小数位,但在第3个小数位,它总是为0.我该怎么做才能解决这个问题,它给了我第三个数字。
print ('Radius Area Circumference')
for Radius in range(1 , 11):
Area = (Radius)**2*3.14
Circumference = (Radius)*2*(3.14)
a = Radius
b = Area
c = Circumference
print ('{:2d} {:10.3f} {:10.3f}'.format(a, (b), (c)))
这是一个如何读出它的例子。
Radius Area Circumference
1 3.140 6.280
2 12.560 12.560
3 28.260 18.840
4 50.240 25.120
答案 0 :(得分:2)
import math
print ('Radius Area Circumference')
for radius in range(1 , 11):
area = radius**2*math.pi
circumference = radius*2*math.pi
print('{:2d} {:10.3f} {:10.3f}'.format(radius, area, circumference))