TypeError:'str'对象不能解释为整数

时间:2017-03-11 07:05:31

标签: python

seniornames =[]
paidornot =[]
for i in range("senior"):
 print("Please enter the name of the Senior Citizen", i+1);
 seniornames.append (input())
 print(seniornames)

有错误说 - 文件“/ Users / rheasethi / Documents / Task 2 pre release.py”,第37行,     我在范围内(“高级”): TypeError:'str'对象不能解释为整数

我该怎么办?

1 个答案:

答案 0 :(得分:0)

range(start, stop[, step])

  

参数必须是普通整数。如果省略step参数,   默认为1.如果省略start参数,则默认为0.

i+1开始,你似乎需要我成为一个整数,所以也许你想要的是:

seniornames =[]
paidornot =[]
for i in range(len("senior")):
    print("Please enter the name of the Senior Citizen", i+1)
    seniornames.append (input())
    print(seniornames)

for i in range(5):
    print("Please enter the name of the Senior Citizen", i+1)
    seniornames.append (input())
    print(seniornames)