Question
Hi, my Python program is caught up in an infinite loop as shown above. The highlighted 'printMembers' method is hanging up, and though I have
Hi, my Python program is caught up in an infinite loop as shown above. The highlighted 'printMembers' method is hanging up, and though I have tried variations of the '(len)' function, it still won't exit the method.
Thank you-
class TeamClass:
name= ""
jersey=""
number=""
def __init__ (self, name, jersey, number):
self.name=name
self.jersey=jersey
self.number=number
#Assignment Methods
def setname(self, name):
self.name=name
def setjersey(self, jersey):
self.jersey=jersey
def setnumber(self, number):
self.number=number
#Retrieval Methods
def getname(self):
return self.name
def getjersey(self):
return(self.jersey)
def getnumber(self):
return(self.number)
#New Addition
def display_member_list(self):
print("Player:")
print("Name:", self.name)
print("Jersey:", self.jersey)
print("Phone Number:", self.number)
print("-------------------")
print("Welcome to the Team Manager")
def printMembers (memberList):
if len(memberList)>0:
print("The members list includes: ")
for j in memberList.keys():
memberList[j].display_member_list()
else:
print("Roster is empty")
def addMember(memberList):
new_member=input("Enter new member: ")
new_jersey=input("Enter jersey#: ")
new_number=input("Enter phone number: ")
memberList[new_member] = TeamClass(new_member, new_jersey, new_number)
def remove(memberList):
deleteItem=input("Enter the name of the member to remove: ")
if deleteItem in memberList:
memberNumber=memberList.index(deleteItem)
del memberList[memberNumber]
else:
print(deleteItem,"was not found in the list")
def editMember(memberList):
editName=input("Enter the name of the member to edit: ")
if editName in memberList:
new_member=input("Enter the new members name: ")
new_jersey=input("Enter new jersey#: ")
new_number=input("Enter new phone number:")
memberList[editName]=TeamClass(new_member, new_jersey, new_number)
print(editName, "has been changed to", new_member)
else:
print(editName, "Was not found in list")
return memberList
memberList=[]
def menu():
print(">>>>")
print("1.Display Team Roster.")
print("2.Add Team Member.")
print("3.Remove Team Member.")
print("4.Edit Team Member.")
print("9.Exit Program.")
selection =int( input("Selection: "))
return selection
memberList={}
selection=menu()
while selection != 9:
if selection==1:
printMembers(memberList)
elif selection ==2:
addMember(memberList)
elif selection ==3:
remove(memberList)
elif selection==4:
editMember(memberList)
else:
print("Please select a valid entry")
5 5 American C ~ Who Create How One C G Get Your O G Home - gra Bb Week 5 Lec GDB online Repl.it. x 10 MIN WA Dad Versus Strategic a C Get Homev + V 0 https://repl.it /languages/Python3 Online Py... Code Python, ... save 8 run share + new repl 88 talk sign up Files main.py saved PI ITL vcl acy. CIT.JCI acy print("Phone Number:", self.number) print("---- ---------") 37 main.py print("Welcome to the Team Manager") def printMembers (memberlist): if len(memberlist)>0: print("The members list includes: ") for j in memberlist.keys(): memberList[j].display_member_list() else: print("Roster is empty") Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty Roster is empty def addMember(memberlist): new_member=input("Enter new member: ") new_jersey=input("Enter jersey#: ") new_number=input("Enter phone number: ") memberlist[new_member] = TeamClass(new_member, new_jersey, new number)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started