所以我有这个计划它在哪里打印所有用户的数据,按照他们输入内容的被输入并给出了相应的信息:如果报表打印错误
nameslist = []
hourslist = []
morestudents = True
while morestudents:
name = raw_input("Enter name : ")
nameslist.append(name)
hours = int(input("enter hours booked : "))
hourslist.append(hours)
more = raw_input("add more students? (yes/no): ")
if more <> "Y" and more <> "y" and more <> "yes" and more <> "Yes":
morestudents = False
print
for x in range (len(nameslist)):
print
print nameslist[x],"You have", hourslist[x], "hours in total"
print
if hourslist >=10 and hourslist <= 14:
print "You have 1 free hour"
elif hourslist >= 15:
print "You have 2 free hours"
elif hourslist <= 9:
print "You have no free hours"
nameslist是所有名的数组输入并且小时是用户输入的整数。无论如何,当我有不止一个人进入他们的时间时,即使他们的时间大于10,它总是打印出“你没有空闲时间”。只有一个人时不会发生此问题。我已经尝试了很多方法来尝试解决这个问题,但没有任何工作,谢谢。
这里是我所得到的:
Enter name : Jack Smith
enter hours booked : 21
add more students? (yes/no): y
Enter name : John Wayne
enter hours booked : 2
add more students? (yes/no): n
Jack Smith You have 23 hours in total
You have no free hours
John Wayne You have 2 hours in total
You have no free hours
的索引。 .. –
有问题的代码与输出不匹配! 'hourlist'将为空,导致'IndexError:列表索引超出范围'。 –
对不起,我忘了这部分hourslist.append(小时) – Hassan