SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 31 Oct 2017 My Price 10.00

it can save to a text file and use a function to load the text file.

How would I change an existing program so that it can save to a text file and use a function to load the text file. I am attaching the code I currently need to change.PLAYERS = {}

# Player class for creating player objects with properties: name, jerseyNo, and phoneNo
class Player:
    name = ''
    jerseyNo = ''
    phoneNo = ''
        
    # constructor
    # def __init__(self, name, jersey, phone):
        # self.name = name;
        # self.jerseyNo = jersey;
        # self.phoneNo = phone;
    
    # mutator method for setting player's name
    def setName(self, name):
        self.name = name

    # mutator method for setting player's jersey number
    def setJerseyNo(self, jersey):
        self.jerseyNo = jersey
        
    # mutator method for setting player's phone number    
    def setPhoneNo(self, phone):
        self.phoneNo = phone
        
    # getter method for getting player's name    
    def getName(self):
        return self.name
        
    # getter method for getting player's jersey number    
    def getJerseyNo(self):
        return self.jerseyNo
        
    # getter method for getting player's phone number    
    def getPhoneNo(self):
        return self.phoneNo

# list players in the team
def list_players():
    if PLAYERS:
        print('Name\t\tJersey\t\tPhone')
        for key, player in PLAYERS.items():
            print(player.getName(),'\t\t',player.getJerseyNo(),'\t\t', player.getPhoneNo())
    else:
        print("Roster is empty")

# add player details to the dictionary
def add_player(name, jersey, phone):
    player_obj = Player()
    player_obj.setName(name)
    player_obj.setJerseyNo(jersey)
    player_obj.setPhoneNo(phone)
    PLAYERS[name] = player_obj
    #print(PLAYERS)

# change player details in the dictionary
def change_player(name):
    if name in PLAYERS:
        player_obj = PLAYERS[name]
        print('Current name: ',player_obj.getName())
        new_name = input("What is the new name: ")
        print('Current jersey number: ',player_obj.getJerseyNo())
        new_jersey = input("What is the new jersey number: ")
        print('Current phone number: ',player_obj.getPhoneNo())
        new_phone = input("What is the new phone number: ")
        player_obj.setName(new_name)
        player_obj.setJerseyNo(new_jersey)
        player_obj.setPhoneNo(new_phone)
        PLAYERS[new_name] = player_obj
        del PLAYERS[name]
        print('Player details were successfully updated')
    else:
        print(name," not found in list")

# remove player details from the dictionary
def remove_player(name):
    if name in PLAYERS:
        del PLAYERS[name]
        print('Removed ',name,' from team list.')
    else:
        print('Name not found in list')


menu_choice = 0
print("Welcome to the Player Roster")
while menu_choice != 9:
        print("-------Menu-------")
        print("1. Show Player List")
        print("2. Add a player to the list")
        print("3. Remove a player from the list")
        print("4. Change a player in the list")
        print("9. Exit Player Roster")
        menu_choice = int(input("Pick an item from the menu: "))

        if menu_choice == 1:
            list_players()
        elif menu_choice == 2:
            name_inp = input("What is the new player's name: ")
            jersey_inp = input("What is the new player's jersey number: ")
            phone_inp = input("What is the new player's phone number: ")
            add_player(name_inp, jersey_inp, phone_inp)
        elif menu_choice == 3:
            del_name = input("What name would you like to remove: ")
            remove_player(del_name)
        elif menu_choice == 4:
            old_name = input("What name would you like to change: ")
            change_player(old_name)
print("Have a Good Day")

Attachments:

Answers

(5)
Status NEW Posted 31 Oct 2017 01:10 PM My Price 10.00

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

Not Rated(0)