SlideShare a Scribd company logo
1 of 7
Download to read offline
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:
include a Save option in the main menu which will prompt the program to write the player’s data
to a text file.
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.
For this project:
You will submit your python code in either the original .py file, or copied into a .txt file.
A screenshot of your code having been executed (run). How to Take a Screenshot
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.
****BELOW IS MY CURRENT WORK*** Im having issues printing the data (printmember)
and saving data. Am I using .keys() wrong? using PYTHON
class Team:
members = {}
member = ""
phone = ""
jersey = 0
def __init__(self, member, phone, jersey):
self.member = member
self.phone = phone
self.jersey = jersey
def setmember(self, member):
self.member = member
def setphone(self, phone):
self.phone = phone
def setjersey(self, jersey):
self.jersey = jersey
def getmember(self, member):
return self.member
def getphone(self, phone):
return self.phone
def getjersey(self, jersey):
return self.jersey
def displayData(self):
print("Name : ", self.member)
print("Phone Number : ", self.phone)
print("Jersey Number : ", self.jersey)
def displayMenu():
print("===========Main Menu===========")
print("1. Display Members.")
print("2. Add member")
print("3. Remove member")
print("4. Edit member")
print("5. Save data.")
print("6. Load data.")
print("7. Exit Program")
return int(input("Selection> "))
def printmember(members):
if len(members) == 0:
print("No current members")
else:
for x in members.keys():
members[x].diaplydata()
def addmember(members):
newMember = input("Enter Members Name : ")
newPhone = int(input("Phone Number : "))
newJersey = int(input("Jersey Number : "))
members[newMember] = (newMember, newPhone, newJersey)
print("Member has been added")
return members
def removemember(members):
removemember = input("Please Enter Member to be Removed : ")
if removemember in members:
del members[removemember]
print("Member removed")
else:
print("Member not found.")
return members
def editmember(members):
oldmember = input("Enter the name of the member you want to edit: ")
if oldmember in members:
newmember = input("Enter the members new name : ")
newphone = int(input("Please enter new phone number : "))
newjersey = input("Please enter new Jersey number : ")
members[newmember] = (newmember, newphone, newjersey)
print("Member edited")
else:
print("Member not found")
return members
def saveData(members):
filename = input("Filename to save: ")
print(" Saving file....")
outFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "wt")
for x in members.keys():
member = members[x].getmember()
phone = members[x].getphone()
jersey = members[x].getjersey()
outFile.write("member , phone , jersey")
print("File saved.")
outFile.close()
return members
def loadData():
members = {}
filename = input("Filename to load: ")
inFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "rt")
print("Loadng file...")
while True:
inLine = inFile.readline()
if not inLine:
break
inLine = inLine[:-1]
member, phone, jersey = inLine.split(",")
members[member] = Team(member, phone, jersey)
print("File loaded!")
inFile.close()
return members
print("Welcome to Feathers Team Manager")
menuSelection = displayMenu()
choice = 1
while choice:
if menuSelection == 1:
printmember(members)
elif menuSelection == 2:
members = addmember(members)
elif menuSelection == 3:
members = removemember(members)
elif menuSelection == 4:
members = editmember(members)
elif menuSelection == 5:
members = saveData(members)
elif menuSelection == 6:
members = loadData(members)
elif menuSelection == 7:
print("Goodbye!")
exit()
menuSelection = displayMenu()
Solution
class Team:
members = {}
member = ""
phone = ""
jersey = 0
def __init__(self, member, phone, jersey):
self.member = member
self.phone = phone
self.jersey = jersey
def setmember(self, member):
self.member = member
def setphone(self, phone):
self.phone = phone
def setjersey(self, jersey):
self.jersey = jersey
def getmember(self, member):
return self.member
def getphone(self, phone):
return self.phone
def getjersey(self, jersey):
return self.jersey
def displayData(self):
print("Name : ", self.member)
print("Phone Number : ", self.phone)
print("Jersey Number : ", self.jersey)
def displayMenu():
print("===========Main Menu===========")
print("1. Display Members.")
print("2. Add member")
print("3. Remove member")
print("4. Edit member")
print("5. Save data.")
print("6. Load data.")
print("7. Exit Program")
return int(input("Selection> "))
def printmember(members):
if len(members) == 0:
print("No current members")
else:
for x in members.keys():
members[x].diaplydata()
def addmember(members):
newMember = input("Enter Members Name : ")
newPhone = int(input("Phone Number : "))
newJersey = int(input("Jersey Number : "))
members[newMember] = (newMember, newPhone, newJersey)
print("Member has been added")
return members
def removemember(members):
removemember = input("Please Enter Member to be Removed : ")
if removemember in members:
del members[removemember]
print("Member removed")
else:
print("Member not found.")
return members
def editmember(members):
oldmember = input("Enter the name of the member you want to edit: ")
if oldmember in members:
newmember = input("Enter the members new name : ")
newphone = int(input("Please enter new phone number : "))
newjersey = input("Please enter new Jersey number : ")
members[newmember] = (newmember, newphone, newjersey)
print("Member edited")
else:
print("Member not found")
return members
def saveData(members):
filename = input("Filename to save: ")
print(" Saving file....")
outFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "wt")
for x in members.keys():
member = members[x].getmember()
phone = members[x].getphone()
jersey = members[x].getjersey()
outFile.write("member , phone , jersey")
print("File saved.")
outFile.close()
return members
def loadData():
members = {}
filename = input("Filename to load: ")
inFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "rt")
print("Loadng file...")
while True:
inLine = inFile.readline()
if not inLine:
break
inLine = inLine[:-1]
member, phone, jersey = inLine.split(",")
members[member] = Team(member, phone, jersey)
print("File loaded!")
inFile.close()
return members
print("Welcome to Feathers Team Manager")
menuSelection = displayMenu()
choice = 1
while choice:
if menuSelection == 1:
printmember(members)
elif menuSelection == 2:
members = addmember(members)
elif menuSelection == 3:
members = removemember(members)
elif menuSelection == 4:
members = editmember(members)
elif menuSelection == 5:
members = saveData(members)
elif menuSelection == 6:
members = loadData(members)
elif menuSelection == 7:
print("Goodbye!")
exit()
menuSelection = displayMenu()

More Related Content

Similar to Until now, you have had to leave your team management program runnin.pdf

Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)
Chandra Pr. Singh
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx
honey690131
 
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdfJava Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
archanaemporium
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
pasqualealvarez467
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
doughellmann
 
Classes(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docxClasses(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docx
brownliecarmella
 

Similar to Until now, you have had to leave your team management program runnin.pdf (20)

Write a task that will perform some of the functions performed by a s.docx
 Write a task that will perform some of the functions performed by a s.docx Write a task that will perform some of the functions performed by a s.docx
Write a task that will perform some of the functions performed by a s.docx
 
Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)
 
Maths with Programming
Maths with ProgrammingMaths with Programming
Maths with Programming
 
Write an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxWrite an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docx
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Python Menu
Python MenuPython Menu
Python Menu
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
 
1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx1 Goals. 1. To use a text file for output and later for in.docx
1 Goals. 1. To use a text file for output and later for in.docx
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
 
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdfJava Program- Wrtie a Fraction classGiven the main method of a dri.pdf
Java Program- Wrtie a Fraction classGiven the main method of a dri.pdf
 
Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Group
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
 
Bangladesh university of business and technology
Bangladesh university of business and technologyBangladesh university of business and technology
Bangladesh university of business and technology
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
Classes(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docxClasses(or Libraries)#include #include #include #include.docx
Classes(or Libraries)#include #include #include #include.docx
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 

More from pearlcoburnsanche303

What are the various methods for recruiting employees Why are some .pdf
What are the various methods for recruiting employees Why are some .pdfWhat are the various methods for recruiting employees Why are some .pdf
What are the various methods for recruiting employees Why are some .pdf
pearlcoburnsanche303
 
Why is mobile computing so important to these three firms Evaluate .pdf
Why is mobile computing so important to these three firms Evaluate .pdfWhy is mobile computing so important to these three firms Evaluate .pdf
Why is mobile computing so important to these three firms Evaluate .pdf
pearlcoburnsanche303
 
What is the waiting time of each process for each of the scheduling a.pdf
What is the waiting time of each process for each of the scheduling a.pdfWhat is the waiting time of each process for each of the scheduling a.pdf
What is the waiting time of each process for each of the scheduling a.pdf
pearlcoburnsanche303
 
The degree of freedom table is available online. Please answer A&B f.pdf
The degree of freedom table is available online. Please answer A&B f.pdfThe degree of freedom table is available online. Please answer A&B f.pdf
The degree of freedom table is available online. Please answer A&B f.pdf
pearlcoburnsanche303
 
the american red cross gives the following distribution for Blood Ty.pdf
the american red cross gives the following distribution for Blood Ty.pdfthe american red cross gives the following distribution for Blood Ty.pdf
the american red cross gives the following distribution for Blood Ty.pdf
pearlcoburnsanche303
 
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdf
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdfSuppose a student mbs a Teflon rod with wool and then briefly touches.pdf
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdf
pearlcoburnsanche303
 
QUESTION 4 Choose true or false as applicable for each of the.pdf
QUESTION 4 Choose true or false as applicable for each of the.pdfQUESTION 4 Choose true or false as applicable for each of the.pdf
QUESTION 4 Choose true or false as applicable for each of the.pdf
pearlcoburnsanche303
 
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdfProblem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
pearlcoburnsanche303
 
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdf
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdfGanges River question The Ganges River, shown in Figure 4.57, has an.pdf
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdf
pearlcoburnsanche303
 
List the three subpathways of cellular respiration and the results o.pdf
List the three subpathways of cellular respiration and the results o.pdfList the three subpathways of cellular respiration and the results o.pdf
List the three subpathways of cellular respiration and the results o.pdf
pearlcoburnsanche303
 

More from pearlcoburnsanche303 (20)

Use the following information to answer questions 1-8. -Identify whet.pdf
Use the following information to answer questions 1-8. -Identify whet.pdfUse the following information to answer questions 1-8. -Identify whet.pdf
Use the following information to answer questions 1-8. -Identify whet.pdf
 
What are the various methods for recruiting employees Why are some .pdf
What are the various methods for recruiting employees Why are some .pdfWhat are the various methods for recruiting employees Why are some .pdf
What are the various methods for recruiting employees Why are some .pdf
 
Why is mobile computing so important to these three firms Evaluate .pdf
Why is mobile computing so important to these three firms Evaluate .pdfWhy is mobile computing so important to these three firms Evaluate .pdf
Why is mobile computing so important to these three firms Evaluate .pdf
 
When a heterozygous plant with round seeds is mated to a plant with .pdf
When a heterozygous plant with round seeds is mated to a plant with .pdfWhen a heterozygous plant with round seeds is mated to a plant with .pdf
When a heterozygous plant with round seeds is mated to a plant with .pdf
 
What is the waiting time of each process for each of the scheduling a.pdf
What is the waiting time of each process for each of the scheduling a.pdfWhat is the waiting time of each process for each of the scheduling a.pdf
What is the waiting time of each process for each of the scheduling a.pdf
 
The mayor of a town has proposed a plan for the construction of an a.pdf
The mayor of a town has proposed a plan for the construction of an a.pdfThe mayor of a town has proposed a plan for the construction of an a.pdf
The mayor of a town has proposed a plan for the construction of an a.pdf
 
PROBLEM 5 Find the inverse of each ofthe following z-transforms .pdf
PROBLEM 5 Find the inverse of each ofthe following z-transforms .pdfPROBLEM 5 Find the inverse of each ofthe following z-transforms .pdf
PROBLEM 5 Find the inverse of each ofthe following z-transforms .pdf
 
The Hazen-Williams hydraulic formula for the mass-flow rate, m throug.pdf
The Hazen-Williams hydraulic formula for the mass-flow rate, m throug.pdfThe Hazen-Williams hydraulic formula for the mass-flow rate, m throug.pdf
The Hazen-Williams hydraulic formula for the mass-flow rate, m throug.pdf
 
The first crop produced by african slave labor in the Caribbean was _.pdf
The first crop produced by african slave labor in the Caribbean was _.pdfThe first crop produced by african slave labor in the Caribbean was _.pdf
The first crop produced by african slave labor in the Caribbean was _.pdf
 
The degree of freedom table is available online. Please answer A&B f.pdf
The degree of freedom table is available online. Please answer A&B f.pdfThe degree of freedom table is available online. Please answer A&B f.pdf
The degree of freedom table is available online. Please answer A&B f.pdf
 
the american red cross gives the following distribution for Blood Ty.pdf
the american red cross gives the following distribution for Blood Ty.pdfthe american red cross gives the following distribution for Blood Ty.pdf
the american red cross gives the following distribution for Blood Ty.pdf
 
Suppose that the probability that a head appears when a coin is tosse.pdf
Suppose that the probability that a head appears when a coin is tosse.pdfSuppose that the probability that a head appears when a coin is tosse.pdf
Suppose that the probability that a head appears when a coin is tosse.pdf
 
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdf
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdfSuppose a student mbs a Teflon rod with wool and then briefly touches.pdf
Suppose a student mbs a Teflon rod with wool and then briefly touches.pdf
 
Review the section Investigating Life Clues to the Origin of Langu.pdf
Review the section Investigating Life Clues to the Origin of Langu.pdfReview the section Investigating Life Clues to the Origin of Langu.pdf
Review the section Investigating Life Clues to the Origin of Langu.pdf
 
QUESTION 4 Choose true or false as applicable for each of the.pdf
QUESTION 4 Choose true or false as applicable for each of the.pdfQUESTION 4 Choose true or false as applicable for each of the.pdf
QUESTION 4 Choose true or false as applicable for each of the.pdf
 
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdfProblem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
Problem 4 Briefly, explain the steps of the Alkaline Lysis “minipre.pdf
 
Please explain In a Drosophila dihybrid cross, a sepia male was mate.pdf
Please explain In a Drosophila dihybrid cross, a sepia male was mate.pdfPlease explain In a Drosophila dihybrid cross, a sepia male was mate.pdf
Please explain In a Drosophila dihybrid cross, a sepia male was mate.pdf
 
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdf
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdfGanges River question The Ganges River, shown in Figure 4.57, has an.pdf
Ganges River question The Ganges River, shown in Figure 4.57, has an.pdf
 
Locomotion is important for many Bacteria Which of the following are .pdf
Locomotion is important for many Bacteria Which of the following are .pdfLocomotion is important for many Bacteria Which of the following are .pdf
Locomotion is important for many Bacteria Which of the following are .pdf
 
List the three subpathways of cellular respiration and the results o.pdf
List the three subpathways of cellular respiration and the results o.pdfList the three subpathways of cellular respiration and the results o.pdf
List the three subpathways of cellular respiration and the results o.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

Until now, you have had to leave your team management program runnin.pdf

  • 1. 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: include a Save option in the main menu which will prompt the program to write the player’s data to a text file. 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. For this project: You will submit your python code in either the original .py file, or copied into a .txt file. A screenshot of your code having been executed (run). How to Take a Screenshot 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. ****BELOW IS MY CURRENT WORK*** Im having issues printing the data (printmember) and saving data. Am I using .keys() wrong? using PYTHON class Team: members = {} member = "" phone = "" jersey = 0 def __init__(self, member, phone, jersey): self.member = member self.phone = phone self.jersey = jersey def setmember(self, member): self.member = member def setphone(self, phone): self.phone = phone def setjersey(self, jersey): self.jersey = jersey def getmember(self, member): return self.member
  • 2. def getphone(self, phone): return self.phone def getjersey(self, jersey): return self.jersey def displayData(self): print("Name : ", self.member) print("Phone Number : ", self.phone) print("Jersey Number : ", self.jersey) def displayMenu(): print("===========Main Menu===========") print("1. Display Members.") print("2. Add member") print("3. Remove member") print("4. Edit member") print("5. Save data.") print("6. Load data.") print("7. Exit Program") return int(input("Selection> ")) def printmember(members): if len(members) == 0: print("No current members") else: for x in members.keys(): members[x].diaplydata() def addmember(members): newMember = input("Enter Members Name : ") newPhone = int(input("Phone Number : ")) newJersey = int(input("Jersey Number : ")) members[newMember] = (newMember, newPhone, newJersey) print("Member has been added") return members def removemember(members): removemember = input("Please Enter Member to be Removed : ") if removemember in members: del members[removemember] print("Member removed")
  • 3. else: print("Member not found.") return members def editmember(members): oldmember = input("Enter the name of the member you want to edit: ") if oldmember in members: newmember = input("Enter the members new name : ") newphone = int(input("Please enter new phone number : ")) newjersey = input("Please enter new Jersey number : ") members[newmember] = (newmember, newphone, newjersey) print("Member edited") else: print("Member not found") return members def saveData(members): filename = input("Filename to save: ") print(" Saving file....") outFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "wt") for x in members.keys(): member = members[x].getmember() phone = members[x].getphone() jersey = members[x].getjersey() outFile.write("member , phone , jersey") print("File saved.") outFile.close() return members def loadData(): members = {} filename = input("Filename to load: ") inFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "rt") print("Loadng file...") while True: inLine = inFile.readline() if not inLine: break inLine = inLine[:-1]
  • 4. member, phone, jersey = inLine.split(",") members[member] = Team(member, phone, jersey) print("File loaded!") inFile.close() return members print("Welcome to Feathers Team Manager") menuSelection = displayMenu() choice = 1 while choice: if menuSelection == 1: printmember(members) elif menuSelection == 2: members = addmember(members) elif menuSelection == 3: members = removemember(members) elif menuSelection == 4: members = editmember(members) elif menuSelection == 5: members = saveData(members) elif menuSelection == 6: members = loadData(members) elif menuSelection == 7: print("Goodbye!") exit() menuSelection = displayMenu() Solution class Team: members = {} member = "" phone = "" jersey = 0 def __init__(self, member, phone, jersey): self.member = member self.phone = phone
  • 5. self.jersey = jersey def setmember(self, member): self.member = member def setphone(self, phone): self.phone = phone def setjersey(self, jersey): self.jersey = jersey def getmember(self, member): return self.member def getphone(self, phone): return self.phone def getjersey(self, jersey): return self.jersey def displayData(self): print("Name : ", self.member) print("Phone Number : ", self.phone) print("Jersey Number : ", self.jersey) def displayMenu(): print("===========Main Menu===========") print("1. Display Members.") print("2. Add member") print("3. Remove member") print("4. Edit member") print("5. Save data.") print("6. Load data.") print("7. Exit Program") return int(input("Selection> ")) def printmember(members): if len(members) == 0: print("No current members") else: for x in members.keys(): members[x].diaplydata() def addmember(members): newMember = input("Enter Members Name : ") newPhone = int(input("Phone Number : "))
  • 6. newJersey = int(input("Jersey Number : ")) members[newMember] = (newMember, newPhone, newJersey) print("Member has been added") return members def removemember(members): removemember = input("Please Enter Member to be Removed : ") if removemember in members: del members[removemember] print("Member removed") else: print("Member not found.") return members def editmember(members): oldmember = input("Enter the name of the member you want to edit: ") if oldmember in members: newmember = input("Enter the members new name : ") newphone = int(input("Please enter new phone number : ")) newjersey = input("Please enter new Jersey number : ") members[newmember] = (newmember, newphone, newjersey) print("Member edited") else: print("Member not found") return members def saveData(members): filename = input("Filename to save: ") print(" Saving file....") outFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "wt") for x in members.keys(): member = members[x].getmember() phone = members[x].getphone() jersey = members[x].getjersey() outFile.write("member , phone , jersey") print("File saved.") outFile.close() return members def loadData():
  • 7. members = {} filename = input("Filename to load: ") inFile = open("/Users/Randy/Desktop/PYCHARM/Week 6/roster.txt", "rt") print("Loadng file...") while True: inLine = inFile.readline() if not inLine: break inLine = inLine[:-1] member, phone, jersey = inLine.split(",") members[member] = Team(member, phone, jersey) print("File loaded!") inFile.close() return members print("Welcome to Feathers Team Manager") menuSelection = displayMenu() choice = 1 while choice: if menuSelection == 1: printmember(members) elif menuSelection == 2: members = addmember(members) elif menuSelection == 3: members = removemember(members) elif menuSelection == 4: members = editmember(members) elif menuSelection == 5: members = saveData(members) elif menuSelection == 6: members = loadData(members) elif menuSelection == 7: print("Goodbye!") exit() menuSelection = displayMenu()