Part of the following python program is suppose to print the names of enrollees for each trainer, however it is printing the names of ALL the enrollees with all the trainers. How can the program be edited to show the names of the enrollees with their particular trainer?
Part of the following python program is suppose to print the names of enrollees for each trainer, however it is printing the names of ALL the enrollees with all the trainers. How can the program be edited to show the names of the enrollees with their particular trainer?
Python Code:
#Trainers/enrollees
#
#The code allows the user to input the number of trainers, the trainer's name, the number of enrollees (up to 15), and the names of each enrollee. The output displays the trainers in each category and the names of the new enrollees.
#Variables - number of trainers, trainers' names, number of enrollees, and names of enrollees
trainers = []
enrollees = []
num_trainers = int(input("How many trainers are there? "))
for i in range(num_trainers):
trainer = input("Enter trainer's name: ")
num_enrollees = int(input("How many enrollees did {} have? ".format(trainer)))
trainers.append([trainer, num_enrollees])
for j in range(num_enrollees):
enrollee = input("Enter enrollee's name: ")
enrollees.append(enrollee)
# print(trainers)
# print(enrollees)
print("Trainers with 0-5 enrollees:")
for trainer in trainers:
if trainer[1] >= 0 and trainer[1] <= 5:
print("- {}".format(trainer[0]))
print (enrollees)
print("Trainers with 6-10 enrollees:")
for trainer in trainers:
if trainer[1] >= 6 and trainer[1] <= 10:
print("- {}".format(trainer[0]))
print (enrollees)
print("Trainers with 11-15 enrollees:")
for trainer in trainers:
if trainer[1] >= 11 and trainer[1] <= 15:
print("- {}".format(trainer[0]))
print (enrollees)
Output (console display):
How many trainers are there? 3
Enter trainer's name: Bob
How many enrollees did Bob have? 5
Enter enrollee's name: a
How many trainers are there? 3
Enter trainer's name: bob
How many enrollees did bob have? 5
Enter enrollee's name: a
Enter enrollee's name: b
Enter enrollee's name: c
Enter enrollee's name: d
Enter enrollee's name: e
Enter trainer's name: tom
How many enrollees did tom have? 6
Enter enrollee's name: f
Enter enrollee's name: g
Enter enrollee's name: h
Enter enrollee's name: i
Enter enrollee's name: j
Enter enrollee's name: k
Enter trainer's name: kym
How many enrollees did kym have? 11
Enter enrollee's name: l
Enter enrollee's name: m
Enter enrollee's name: n
Enter enrollee's name: o
Enter enrollee's name: p
Enter enrollee's name: q
Enter enrollee's name: r
Enter enrollee's name: s
Enter enrollee's name: t
Enter enrollee's name: u
Enter enrollee's name: v
Trainers with 0-5 enrollees:
- bob
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v']
Trainers with 6-10 enrollees:
- tom
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v']
Trainers with 11-15 enrollees:
- kym
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v']
Step by step
Solved in 3 steps with 2 images