The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
How do I replace?
Programming Essentials
Team Management OOP Style
Your program for keeping track of team members is coming along, but now you want to be able to include phone numbers and jersey numbers along with your team member’s name. Modify your program from week 4 so that the program utilizes object-oriented programming to create a member object which can accept the player’s name, phone number, and jersey number. You will need to replace the list with a dictionary to help in locating objects for removal and editing. Again, File Access for long-term storage is not required for this assignment.
For this project:
Tips:Â While dictionaries resemble lists, remember that they are not the same! It is better to use FOR loops, not WHILE loops with index values.
Your class structure does not need a full set of accessor and mutator methods getName(), setName(newName), however it they will be helpful in the next week.
# managing the softball team
Â
memberList = []
def memberadd(membername):
     if membername in memberList:
           print ('Can\'t add because memmber already exists.\n')
     else:
           memberList.append(membername)
Â
def memberremove(membername):
     if membername in memberList:
           memberList.remove(membername)
     else:
           print('Can\'t remove because member doesn\'t exist.\n')
Â
def memberedit(membername):
     if membername not in memberList:
           print('Can\'t edit because member doesn\'t exist\n')
     else:
           i = memberList.index(membername)
           tname = input('Enter the new name of the member: ')
           if tname not in memberList:
                 memberList[i] = tname
           else:
                 print ('Can\'t replace with already existing player\n')
Â
def displayroster():
     print('\n')
     if len(memberList) == 0:
           print ('No members are in roster\n')
     for member in memberList:
           print(member)
     print ('\n')
Â
print ('Welcome to the Team Manager\n')
user_input = '-1'
while (user_input != '9'):
     print('==========Main Menu==========')
     print ('\n1. Display Team Roster')
     print ('2. Add member')
     print ('3. Remove member')
     print ('4. Edit member')
     print ('9. Exit program')
     user_input = input('Selection> ')
     if (user_input == '1'):
           displayroster()
     elif (user_input == '2'):
           membername = input ('Enter new member\'s name: ')
           memberadd(membername)
     elif (user_input == '3'):
           membername = input ('Enter member name to be removed: ')
           memberremove(membername)
     elif (user_input == '4'):
           membername = input ('Enter the name of the member you want to edit: ')
           memberedit(membername)
     elif (user_input == '9'):
           print ('Exiting Program...')
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly