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?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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']

main.py x
Console Shell
3 #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
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? o
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: 1
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
enrollee. The output displays the trainers in each category and the names of the new enrollees.
4 #Variables - number of trainers, trainers' names, number of enrollees, and names of enrollees
5
trainers = n
enrollees = []
8 num_trainers = int(input( "How many trainers are there? "))
10 v for i tn range( num_trainers):
11
12
trainer = input( "Enter trainer's name: ")
13
14
num_enrollees = int(input( "How many enrollees did {} have? ". format(trainer)))
15
16
trainers.append( [trainer, num_enrollees])
17
18 v for j in range(num_enrollees):
19
20
enrollee = input( "Enter enrollee's name: ")
21
22
enrollees.append(enrollee)
23
24
# print(trainers)
Enter enrollee's name:t
Enter enrollee's name: u
Enter enrollee's name: V
Trainers with 0-3 enrollees:
- bob
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
Trainers with ó-10 enrollees:
25
26
# print(enrollees)
27
28
print("Trainers with 0-5 enrollees:")
29
's', 't', 'u', 'v']
30 v for trainer in trainers:
tom
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
Trainers with 11-15´enroílees:
kym
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
31
'q', 'r', 's', 't', 'u', 'v']
32 v if trainer[1] >= 0 and trainer[1] <= 5:
33
'i', 'j',
'l', 'm'
's', 't', 'u', 'v']
34
print("- {}".format(trainer[0]))
35
print (enrollees)
36
37 print("Trainers with 6-10 enrollees:")
38
39 v for trainer in trainers:
40
41 v if trainer[1] >= 6 and trainer[1] <= 10:
42
43
print("- {}".format(trainer[0]))
print (enrollees)
45
46 print( "Trainers with 11-15 enrollees:")
47
48 v for trainer in trainers:
49
50 v if trainer[1] >= 11 and trainer[1] <= 15:
51
52
print("- {}".format(trainer[0]))
53
print (enrollees)
Transcribed Image Text:main.py x Console Shell 3 #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 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? o 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: 1 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 enrollee. The output displays the trainers in each category and the names of the new enrollees. 4 #Variables - number of trainers, trainers' names, number of enrollees, and names of enrollees 5 trainers = n enrollees = [] 8 num_trainers = int(input( "How many trainers are there? ")) 10 v for i tn range( num_trainers): 11 12 trainer = input( "Enter trainer's name: ") 13 14 num_enrollees = int(input( "How many enrollees did {} have? ". format(trainer))) 15 16 trainers.append( [trainer, num_enrollees]) 17 18 v for j in range(num_enrollees): 19 20 enrollee = input( "Enter enrollee's name: ") 21 22 enrollees.append(enrollee) 23 24 # print(trainers) Enter enrollee's name:t Enter enrollee's name: u Enter enrollee's name: V Trainers with 0-3 enrollees: - bob ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', Trainers with ó-10 enrollees: 25 26 # print(enrollees) 27 28 print("Trainers with 0-5 enrollees:") 29 's', 't', 'u', 'v'] 30 v for trainer in trainers: tom ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', Trainers with 11-15´enroílees: kym ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 31 'q', 'r', 's', 't', 'u', 'v'] 32 v if trainer[1] >= 0 and trainer[1] <= 5: 33 'i', 'j', 'l', 'm' 's', 't', 'u', 'v'] 34 print("- {}".format(trainer[0])) 35 print (enrollees) 36 37 print("Trainers with 6-10 enrollees:") 38 39 v for trainer in trainers: 40 41 v if trainer[1] >= 6 and trainer[1] <= 10: 42 43 print("- {}".format(trainer[0])) print (enrollees) 45 46 print( "Trainers with 11-15 enrollees:") 47 48 v for trainer in trainers: 49 50 v if trainer[1] >= 11 and trainer[1] <= 15: 51 52 print("- {}".format(trainer[0])) 53 print (enrollees)
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY