Criteria¶
Follows the interaction example in the task and passes the autograder tests.
Code is easy to follow, e.g.:
no code duplication (by using functions)
relatively long code is broken down in functions
no deeply nested logic where a simpler structure works
The code is commented where the why is not obvious.
Variable names
are meaningful
follow one consistent convention: camel case or snake case
Numbers with a special meaning have a name.
(recommended) Only the programming structures introduced so far are used.[1]
Used exceptions where appropriate, e.g., in user input conversions.
You separate GUI functionality and business or game logic (backend).
Your GUI code is structured in a grid and the structure is also somewhat identifiable in your code through formatting.
Recipe v2¶
Rock Paper Scissors GUI¶
Inventory v2¶
(30-60 min) Add the following subclasses to Exercise 3:
HardItemis for substancesunit_weight: aDecimal
BulkItemis a non-countable item measured and sold in meters, kg etc.measurement_unit: a string
LicenseItemis for softwarevalidity_duration:timedelta, e.g, 26 weeksexpires_at(purchase_date: datetime)returns thedatetimewhen the license expires
Name your new module inventory_v2.py and test it with inventory_v2_test.py. Include your updated class diagram as inventory_v2.svg or *.png.
def process_order():
if order_book.process_next_order():
print("Order processed.")
else:
print("Order cannot be fulfilled or there are no orders left.")
print(f"Total revenue: {order_book.total_revenue()}")
print()
process_order()
process_order()
print("Filling up stock")
inventory.stock[item2] += 10
process_order()
process_order()
process_order()
process_order()
Test program — only relevant lines are shown
Order processed.
Total revenue: 80
Order cannot be fulfilled or there are no orders left.
Total revenue: 80
Filling up stock
Order processed.
Total revenue: 291.21
Order processed.
Total revenue: 312.42
Order processed.
Total revenue: 50312.42
Order cannot be fulfilled or there are no orders left.
Total revenue: 50312.42
Expected output
Whole inventory_v2_test.py
from datetime import datetime, timedelta
from inventory_v2 import *
item1 = Item(id="hydraulic pump", price_per_unit=Decimal("20"))
item2 = BulkItem(
id="lubrication oil",
price_per_unit=Decimal("10.1"),
unit_weight=Decimal("0.9"),
measurement_unit="l",
)
item3 = HardItem(id="pen", price_per_unit=Decimal("1.1"), unit_weight=Decimal(".001"))
item4 = LicenseItem(
id="Power Plus",
price_per_unit=Decimal("10_000"),
validity_duration=timedelta(weeks=52),
)
inventory = Inventory()
inventory.stock = {
item1: Decimal("10"),
item2: Decimal("1"),
item3: Decimal("500"),
item4: Decimal("Infinity"),
}
order_line1 = OrderLine(item=item1, quantity=Decimal("4"))
order_line2 = OrderLine(item=item2, quantity=Decimal("2.1"))
order_line3 = OrderLine(item=item3, quantity=Decimal("100"))
order_line4 = OrderLine(item=item4, quantity=Decimal("5"))
order1 = Order(time=datetime.now() - timedelta(days=3), order_lines=[order_line1])
order2 = Order(
time=datetime.now() - timedelta(days=2),
order_lines=[order_line1, order_line2, order_line3],
)
order3 = Order(time=datetime.now(), order_lines=[order_line2])
order4 = Order(time=datetime.now(), order_lines=[order_line4])
customer1 = Customer(id="Ramanda")
customer2 = Customer(id="Totoro")
order_book = OrderBook(inventory)
customer1.create_order(order_book, order1)
customer2.create_order(order_book, order2)
customer2.create_order(order_book, order3)
customer1.create_order(order_book, order4)
def process_order():
if order_book.process_next_order():
print("Order processed.")
else:
print("Order cannot be fulfilled or there are no orders left.")
print(f"Total revenue: {order_book.total_revenue()}")
print()
process_order()
process_order()
print("Filling up stock")
inventory.stock[item2] += 10
process_order()
process_order()
process_order()
process_order()
Inventory v2 GUI¶
(1-3h) Implement a GUI for Exercise 3. It should at least be able to process orders as shown in Figure 2.
Figure 2:A minimal GUI with Treeviews, labels, and a button.
You are encouraged to add a tab for the inventory and customers.
Implement
inventory_v2_gui.py, whichimports
inventory_v2.pyCreates an example
OrderBook. You can copy paste relevant lines frominventory_v2_test.pyfrom Exercise 3.Configures and instantiates your GUI that uses the data from
OrderBook
Record your app similar to Figure 2 and store it as
inventory_v2_gui.mov,*.mp4, or*.webm.Which classes can be directly reflected in the GUI and which should be modified to better be viewed on a GUI? Write your thoughts in
inventory_v2_gui.txt. Few sentences are plenty.
You may already know more advanced concepts. Sticking to what we’ve covered so far trains you to solve problems with a limited toolbox, and it means you face the same challenges as your classmates, so you can help each other. This criterion is optional; the choice is yours.