我试图给我的格式化答案一个名字,但它不起作用

时间:2013-11-07 14:51:47

标签: python format

 for x in range(1.11):
    print ('Number: {0:2d} Square: {1:3d} Cube: {2:4d}'.format(x, x*x, x*x*x))

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    for x in range(1.11):
TypeError: 'float' object cannot be interpreted as an integer

1 个答案:

答案 0 :(得分:0)

您在.中使用,代替for x in range(1.11):它应该显示为:

for x in range(1,11):
    print ('Number: {0:2d} Square: {1:3d} Cube: {2:4d}'.format(x, x*x, x*x*x))