# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("1_practicequiz_q", "week_7", "practicequiz", assignment_points = 28.0, assignment_tag = 'week7-practicequiz')
# Initialize Otter
import otter
grader = otter.Notebook("1_practicequiz_q.ipynb")
โA Manufacturing System using Object-Oriented Programming#

# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._1_practicequiz_q import Question3
Question3().show()
Question 1 (Points: 12.0): Modify an Inventory Class#
Given the Inventory class below, modify it to:
Add an
__init__()method that initializes thenameandstockattributes. Thestockattribute should default to 0.Add an
add_stock(quantity)method that increases thestockattribute.Add a
remove_stock(quantity)method that decreasesstockbut ensures it doesnโt go below zero.Implement a
__str__()method that returns"Product: <name>, Stock: <stock>".
Example:#
item = Inventory("Gears", 50)
item.add_stock(20)
print(item) # Output: Product: Gears, Stock: 70
item.remove_stock(80)
print(item) # Output: Product: Gears, Stock: 0
...
# Example usage
item = Inventory("Gears", 50)
item.add_stock(20)
print(item)
item.remove_stock(80)
print(item)
grader.check("Free-Response-Modify-an-Inventory-Class")
Submitting Assignment#
Please run the following block of code using shift + enter to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week7-practicequiz", "1_practicequiz_q")