简体   繁体   中英

I'm trying to give my formatted answer a name and it's not working

 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

You use a . instead of a , in for x in range(1.11): It should read:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM