Question

In: Computer Science

Until now, you have had to leave your team management program running on your computer indefinitely...

Until now, you have had to leave your team management program running on your computer indefinitely since you did not want to lose the list of players. Finally, you are ready to add the components to your team management program that will allow you to store the player’s information on your computer’s hard drive, thus, allow you to shut down your program without losing your data.

You will need to modify your program to:

  1. include a Save option in the main menu which will prompt the program to write the player’s data to a text file.
  2. modify the startup code so that the program calls a function that reads the player’s data from the text file into the list of member objects.

Tips: Think about how you are going to write the data to the text file when you create the load function. Your write function needs to read in the data in the same pattern as the load function, otherwise the data will get jumbled.

Sample output:

C:\>python week6.py

Welcome to the Team Manager

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 2

Enter new member's name: Nathan

Contact phone number: 505-908-0670

Jersey number: 21

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 2

Enter new member's name: Bobby

Contact phone number: 541-241-0670

Jersey number: 44

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 5

Filename to save: members.txt

Saving data...

Data saved.

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 9

Exiting Program...

C:\>python week6.py

Welcome to the Team Manager

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 1

No current members in memory.

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 6

Filename to load: members.txt

Loading data...

Data Loaded Successfully.

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection> 1

Name: Bobby

Phone: 541-241-0670

Jersey Number: 44

Name: Nathan

Phone: 505-908-0670

Jersey Number: 21

===========Main Menu===========

1. Display Team Roster.

2. Add Member.

3. Remove Member.

4. Edit Member.

5. Save Data.

6. Load Data.

9. Exit Program.

Selection>9

Exiting Program...

Solutions

Expert Solution

If you have any doubts, please give me comment...

def addmember(players, name, phone, jersey_num):

    players.append({'name':name, 'phone':phone, 'jersey_num':jersey_num})

    return players


def display(players):

    if(len(players)==0):

        print("No current members in memory.")

    else:

        for player in players:

            print("Name: "+player['name']+"\nPhone: "+player['phone']+"\nJersey Number: "+str(player['jersey_num']))


def removemember(players, name):

    players.remove(name)

    return players


def editname(players, oldname, newname, phone, jersey_num):

    newplayers = []

    for player in players:

        if player['name'] == oldname:

            if(phone==""):

                phone = player['phone']

            if(jersey_num == ""):

                jersey_num = player['jersey_num']

            newplayers.append({'name':newname, 'phone':phone, 'jersey_num':jersey_num})

        else:

            newplayers.append(player)

    return newplayers

def load(filename, players):

    try:

        fp = open(filename)

        print("Loading data...")

        for line in fp.readlines():

            cols = line.strip().split(",")

            cols[2] = int(cols[2])

            players.append({'name':cols[0], 'phone':cols[1], 'jersey_num':cols[2]})

        fp.close()

        return players

    except FileNotFoundError:

        print("Unable to open file")

        return []

def save(filename, players):

    fp = open(filename, "w+")

    print("Saving data...")

    for player in players:

        print(player['name']+","+player['phone']+","+player['jersey_num'], file=fp)

    fp.close()

players = []

while True:

    print("Welcome to the Team Manager")

    print("===========Main Menu===========")

    print("1. Display Team Roster.")

    print("2. Add Member")

    print("3. Remove Member")

    print("4. Edit Member")

    print("5. Save Data.")

    print("6. Load Data.")

    print("9. Exit Program")

    # get the choice

    ch = int(input('<Selection>'))

    # if else block

    if ch == 1:

        display(players)

    elif ch == 2:

        name = input("Enter new member's name:")

        phone = input("Contact phone number: ")

        jersey_num = input("Jersey number: ")

        players = addmember(players, name, phone, jersey_num)

    elif ch == 3:

        name = input("Enter member name to be removed:")

        players = removemember(players, name)

    elif ch == 4:

        oldname = input("Enter the name of the member you want to edit:")

        newname = input("Enter the new name of the member:")

        phone = input("Enter new phone number(leave empty to unchange):")

        jersey_num = input("Enter new phone number(leave empty to unchange):")

        players = editname(players, oldname, newname, phone, jersey_num)

    elif ch==5:

        filename = input("Filename to save: ")

        save(filename, players)

        print("Data saved.")

    elif ch==6:

        filename = input("Filename to load: ")

        players = load(filename, players)

        print("Data Loaded Successfully.")

    elif ch == 9:

        print("Exiting Program...")

        break


Related Solutions

You and your team are now working on some icons for the organization’s program user interface...
You and your team are now working on some icons for the organization’s program user interface (UI). Based on your first mock-up of the UI, complete the following: Discuss 2 original icons with 3 states each. Explain how the icons would be used, and give the purpose of each state. Investigate emerging alternative I/O devices and discuss their impacts on design.
have you considered the risks in creating your management team? Explain.
have you considered the risks in creating your management team? Explain.
What is your personal theory of nursing? If you have never thought about it until now,...
What is your personal theory of nursing? If you have never thought about it until now, just start somewhere. It doesn't need to be more than a couple of paragraphs long and there are no right or wrong answers.
Imagine that you are part of the management team for Econsoft, a computer software company. You...
Imagine that you are part of the management team for Econsoft, a computer software company. You are discussing one of your products, “Econblaster,” with the company’s CEO and the other managers. You have made the software available for download on your firm’s website for download for $9.99 and you are trying to figure out how to generate more revenue from the product. Half of the management team suggests increasing the price to $11.99. The other half advocates cutting the price...
You have been asked to oversee the management of risk for your team or department at...
You have been asked to oversee the management of risk for your team or department at work, where an expansion process is currently being considered. If you do not have an example you can draw upon, you are able to make up an example as long as you demonstrate your understanding on what is requested. You will need to identify the key stakeholders with whom you will communicate and conduct the stakeholder analysis. You have been supplied a template to...
You have been tasked by your upper management team to give a presentation to your peers...
You have been tasked by your upper management team to give a presentation to your peers on heath disparities and inequalities. In this assignment, you will create a PowerPoint presentation to evaluate the impact of commonly accepted business principles used to create an equitable healthcare system. Your presentation should include discussion on the following topics: definitions and examples, ethical differences between an inequality and an inequity, populations involved, ways to reduce or eliminate health inequalities, and business principles and ethical...
If you owned a restaurant, identify the key employees you would have for your management team...
If you owned a restaurant, identify the key employees you would have for your management team and describe how they should be managed including managing competencies, managing behaviors, and managing the work environment.
The team agrees that the goal is to have a winning boat ready to leave for...
The team agrees that the goal is to have a winning boat ready to leave for the competition in 45 weeks at a cost of $3.2 million. Design of the hull, deck, mast, and accessories will initiate the boat construction. After the design is complete, the hull can be constructed, the mast ordered, sails ordered, and accessories ordered. As soon as the hull is finished, the ballast tanks can be installed. Then the deck can be built. Concurrently with the...
Now that operations for outdoor clinics and TEAM events are running smoothly, Suzie thinks of another...
Now that operations for outdoor clinics and TEAM events are running smoothly, Suzie thinks of another area for business expansion. She notices that a few clinic participants wear multiuse (MU) watches. Beyond the normal timekeeping features of most watches, MU watches are able to report temperature, altitude, and barometric pressure. MU watches are waterproof, so moisture from kayaking, rain, fishing, or even diving up to 100 feet won’t damage them. Suzie decides to have MU watches available for sale at...
Now that operations for outdoor clinics and TEAM events are running smoothly, Suzie thinks of another...
Now that operations for outdoor clinics and TEAM events are running smoothly, Suzie thinks of another area for business expansion. She notices that a few clinic participants wear multiuse (MU) watches. Beyond the normal timekeeping features of most watches, MU watches are able to report temperature, altitude, and barometric pressure. MU watches are waterproof, so moisture from kayaking, rain, fishing, or even diving up to 100 feet won’t damage them. Suzie decides to have MU watches available for sale at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT