In the Basta Fazoolin project of the Classes lesson for Python. I’m stuck at task 10 where it askes me to test out .calculate bill.
I followed the video walkthrough but I keep getting the following error:
Traceback (most recent call last):
File “script.py”, line 40, in
print(brunch.calculate_bill([‘pancakes’,‘home fries’]))
File “script.py”, line 13, in calculate_bill
for purchased_item in purchased_items:
NameError: name ‘purchased_items’ is not defined
I’m really stuck here and I’ve never been previously stuck like this during previous lessons. It’s been really hard for me to understand the concept of classes
Unfortunately the code formatting thing is too complicated for me right now. But I can tell you why I suspect a bug.
when inputting the Function to calculate the bill:
def calculate_bill(self, puchased_items):
bill = 0
for purchased_item in purchased_items:
if purchased_item in Self.items:
bill += self.items[purchased_item]
return bill
Did the above as instructed by the walkthrough. It does not produce any errors when I click save.
The moment I input the code to call the function:
brunch.calculate_bill([‘pancakes’,‘home fries’])
That error occurs stating that purchased_items is not defined.