i can enter inputs for one go through. It gives me the index error after entering my second lastNames input. Why is it doing this? index should be at 1 for this. The range is 15, why is it doing this? how do i fix it?
code is below:
#Purpose: Take in 15 inputs for a trainers last name and the amount of new members they
enrolled, then output how many trainers got a certain indicated amount of enrollees.
LIMIT = 15
lastNames = [LIMIT]
enrollees = [LIMIT]
index = 0
membersZeroFive = 0
membersSixTen = 0
membersElevenFifteen = 0
while index < 16 :
lastNames[index] = input("Enter your last name, trainer. \n")
enrollees[index] = input("How many new members were you able to enroll? \n")
if enrollees[index] == '0' or '1' or '2' or '3' or '4' or '5' :
membersZeroFive = membersZeroFive 1
if enrollees[index] == '6' or '7' or '8' or '9' or '10' :
membersSixTen = membersSixTen 1
if enrollees[index] == '11' or '12' or '13' or '14' or '15' :
membersElevenFifteen = membersElevenFifteen 1
else :
print("your number is either above 15 or negative. I can not operate with such values. Please take note and run the program again.\n")
index = index 1
print("Trainers who got 0-5 members: " membersZeroFive)
print("Trainers who got 6-10 members: " membersSixTen)
print("Trainers who got 11-15 members: " membersElevenFifteen)
CodePudding user response:
lastNames = enrollees = [15]
Your assignation is incorrect, only have a list of size 1. I think, that's the reason of your error. You have to create a list with size of 15.
This is a question that can help you: Create an empty list in Python with certain size