Python I';我试着给我的格式化答案起个名字,然后它';它不工作了 范围(1.11)内x的: 打印('Number:{0:2d}正方形:{1:3d}立方体:{2:4d}'。格式(x,x*x,x*x*x)) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 对于范围(1.11)内的x: TypeError:“float”对象不能解释为整数

Python I';我试着给我的格式化答案起个名字,然后它';它不工作了 范围(1.11)内x的: 打印('Number:{0:2d}正方形:{1:3d}立方体:{2:4d}'。格式(x,x*x,x*x*x)) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 对于范围(1.11)内的x: TypeError:“float”对象不能解释为整数,python,format,Python,Format,对于范围(1.11)内的x,在中使用而不是,应为: 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): TypeEr

对于范围(1.11)内的x,在
中使用
而不是
应为:

 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
for x in range(1,11):
    print ('Number: {0:2d} Square: {1:3d} Cube: {2:4d}'.format(x, x*x, x*x*x))