For this assignment, you are going to pretend that you are writing a phone book application that stores names and phone numbers.

In order to do this, you are going to create a Phonebook class that contains the appropriate program logic to store a list of dictionaries where each dictionary contains name, phone number, and what type of phone number is being stored. Your class must include validation to ensure the following:

  • That the user's first and last names are letters only
  • That phone numbers are numeric only and 10 digits long
  • That the phone number type is only one of the following: "home", "office", or "cell"

The rest of your implementation details are up to your discretion, applying the things you have learned about Python so far. Please note, however, that you must organize your class into a module and produce documentation (using Pydoc) for your work using the principles discussed earlier in the class. Any applicable exception handling in your code must be done according to the principles previously discussed.

Homework Problems

Problem 1:

Write a function that accepts two parameters: course ID (e.g. IT 412) and the semester the course is to be taken in (e.g. Fall 2050). The function should return a dictionary of the form {course: < provided course ID>, semester: < provided semester>}. Thus, for a course ID of IT 412 and a semester of Fall 2050, the return should be:

{course: "IT 412", semester: "Fall 2050"}

Store the function in its own file. Next, create another file that you will use to test your new function. Write a test case class and create a method on it to ensure that the function returns data in the correct format. Make sure that when you write your class that you run it and your test passes.

Problem 2:

Write a class called InventoryItem. The constructor for the class should take in a product ID, a product name, and current quantity available. Each of these values should be stored as an attribute on the class.

Write a method called "buy_item" that takes the current quantity available property and reduces it by one by default. Code your method so that this default can be overridden.

Now, write a test case class for your InventoryItem class. Write two test methods, one to test the default behavior and one to test what happens when the default behavior is overridden. In your test class, leverage the setUp() method technique described in the textbook so you only have to instantiate your InventoryItem class once. Lastly, run your test case class and ensure that both tests pass.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.