Kodewick
Start learning →
Basic←→0 / 80

Fridge clear-out

#059BasicClassesLists4 min

Each thing in the fridge is (name, days since opening, days it keeps once open). to_throw_out turns them into Food objects and picks the ones to bin. Finish too_old(): return True when it has been open for more days than it keeps; exactly equal is still fine.

Examples
to_throw_out([("milk", 5, 4), ("jam", 10, 30), ("bread", 3, 3)])→['milk']
to_throw_out([])→[]
main.py
class Food:
    def __init__(self, name, days_open, keeps):
        self.name = name
        self.days_open = days_open
        self.keeps = keeps

    def too_old(self):
        # your code here: compare the two numbers of days and return True or False
        return False


def to_throw_out(fridge):
    foods = [Food(name, days, keeps) for name, days, keeps in fridge]
    return [f.name for f in foods if f.too_old()]
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.