Question

In: Computer Science

Write in Python. come up with a programming task for which you will write your own...

Write in Python.

come up with a programming task for which you will write your own program. It should be a purposeful and non-trivial program, bigger than any programming assignment. But it should not be something too ambitious that you may not end up finishing by the deadline. The program must not be something available on the Internet or in a book. The program must satisfy the following five requirements:

  1. It must define and appropriately use at least one class.
  2. It must use at least two meaningful functions besides main function and the class methods.
  3. Its input and output must be through files (some user input, or output to screen is ok in addition, if needed)
  4. It must use at least one list or one dictionary.
  5. The program must be well documented with module documentation (three double-quote comments) for functions and classes as well as comments at appropriate places in the program.

Please feel free to contact the instructor if any help is needed at any stage of the project.

Submission:

  1. Submit your .py program file(s)
  2. Submit sample input/output file as needed
  3. Submit a plain text file called README.txt that clearly explains:
    • The programming task and its specifications
    • Your programming design (e.g. what part of the program does what)
    • How to run your program

Solutions

Expert Solution

#class phonebook, that will read phonebook from a file, and load it to a dictionary
class PhoneBook:
#class constructor
def __init__(self):
try:
#reading from the file
f = open('phonebook.txt', 'r')
data = f.readlines()
pb = {}
#populating dictionary
for line in data:
line = line.split(',')
pb.update({line[0].strip(): line[1].strip()})
self.phonebook = pb
f.close()
except FileNotFoundError:
self.phonebook = {}
  
#function to get phone number by name
def getPhoneNumber(self, name):
if name in self.phonebook.keys():
return self.phonebook[name]
else:
return "Name not in Phone book"
  
#function to get name by phone number
def getName(self, phone_number):
for name, number in self.phonebook.items():
if number == phone_number:
return name
return "Number not in phonebook"
  
#function to add a new contact in the phonebook
def addContact(self, name, number):
self.phonebook.update({name: number})
f = open('phonebook.txt', 'w')
for name, number in self.phonebook.items():
f.write(name +", " + number + "\n")
f.close()
return "Contact Added Successfully"

#function to display menu to user and return the choice entered by user
def menu():
print("1. Get Phone number by name.")
print("2. Get name by phone number.")
print("3. Add a new contact in phonebook.")
print("0. Exit")
ch = int(input("Enter your choice: "))
return ch

#function to perform operation based on user choice
def operation(pb, ch):
if ch == 1:
name = input("Enter Name: ")
print(name, ':', pb.getPhoneNumber(name))
elif ch == 2:
number = input("Enter Phone number: ")
print(number, ':', pb.getName(number))
elif ch == 3:
name = input("Enter Name: ")
number = input("Enter Phone number: ")
pb.addContact(name, number)

#main function
def main():
#create object of phonebook class
pb = PhoneBook()
ch = menu()
while ch != 0:
operation(pb, ch)
print("")
ch = menu()
main()

phonebook.txt

Shashank Shukla, 123456789
Abhiram, 456789123
Dale, 45685217
Nathan, 78954213
george, 4861265
Sarah, 45645123
Carrie, 786523
Aria, 777777777


Related Solutions

For this discussion, come up with your own definition for the terms that refer to a,...
For this discussion, come up with your own definition for the terms that refer to a, "For-profit Enterprise", a "Non-profit Enterprise", and a "Social Enterprise". Feel free to share what you have learned and any relevant facts that you find along the way.
Please also write one of your own C programming with for loop which will be assigned...
Please also write one of your own C programming with for loop which will be assigned to multiple threads. Using dynamic scheduling.
What is a prophet? Come up with one of your own in a sentence or two....
What is a prophet? Come up with one of your own in a sentence or two. In addition to your definition of a prophet, what is it that makes the figure you chose prophetic , and how does his/her story reflect a social justice principle or principles? What is that moves this person to act and speak?
For this homework assignment, the task is to come up with a way to test the...
For this homework assignment, the task is to come up with a way to test the hypothesis that internet use impairs classroom performance experimentally. 1 What experimental design will you use to test the hypothesis? (2 points)             2 Why did you decide to use this particular design? What specific threats to validity guided your choice of experimental design? (4 points) 3 How will you operationalize your independent variable? Here you first have to define the construct (so that we...
1. In 3 to 4 sentences, come up with your own personal ethical principle/philosophy which upholds...
1. In 3 to 4 sentences, come up with your own personal ethical principle/philosophy which upholds over the years. 2. What other ethical principle/philosophy you want to embrace as ypu grow older? State it in 2 to 4 sentences.
1) Come up with your own story to illustrate Russel’s paradox informally.
1) Come up with your own story to illustrate Russel’s paradox informally.
18. State and explain the Coase Theorem. Come up with an example of your own for...
18. State and explain the Coase Theorem. Come up with an example of your own for which the Coase Theorem might best apply and explain how it would happen to solve the externality. Change your scenario in one small way to show how the Coase Theorem would collapse.
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
Use the scientific method to come up with, and create your own testable experiment. The experiment...
Use the scientific method to come up with, and create your own testable experiment. The experiment must involve something dealing with cancer, and it must be testable in a lab setting. Remember to include illustrations on how the experiment can be tester. Be sure to include and label your "Observation", "Hypothesis","Experiment", Data & Analyis", & "Conclusion".
For this project you need to come up with five what-ifs. You should use your own house if you have one.
For this project you need to come up with five what-ifs. You should use your own house if you have one. For instance you buy a $500,000 house, put 25% down and finance the rest at 5.5% for 30 years. Now suppose that after 15 years you decide to refinance at 4.7% for 30 years. How much would you save? Now jump to the bottom line and figure how much you save. Is there any ah hah moments? What if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT