Basta Fazoolin' step 11

Hi Fellow Code Academiers,

I am experiencing an issue with step 11 of the Basta Fazoolin’ project. I have cut and pasted the code into geany on my rig and run the code and the correct results are displayed. But when I run it from within the project environment, it displays only a value of $8 for the purchase total. I have tried vizualize python site and I don’t know what is going on with them but their certificate is according to Firefox invalid and cannot get it to work.
I have included a link to my code on the viz python site: Fazoolin’

class Menu():
  def __init__(self, name, items, start_time, end_time): = name
    self.items = items
    self.start_time = start_time
    self.end_time = end_time
  def __repr__(self):
    return + ' menu is available between: ' + str(self.start_time) + ' and ' + str(self.end_time) + ' hours.'
  def calculate_bill(self, purchased_items):
    bill = 0
    for purchased_item in purchased_items:
        if purchased_item in self.items:
#          print(self.items)
          bill += self.items[purchased_item]
#          print(purchased_item)
    return bill
brunch_items = { 'pancakes': 7.50, 'waffles': 9.00, 'burger': 11.00, 'home fries': 4.50, 'coffee': 1.50, 'espresso': 3.00, 'tea': 1.00, 'mimosa': 10.50, 'orange juice': 3.50 }
brunch_menu = Menu('Brunch', brunch_items, 1100, 1600)
early_bird_items = {
  'salumeria plate': 8.00, 'salad and breadsticks (serves 2, no refills)': 14.00, 'pizza with quattro formaggi': 9.00, 'duck ragu': 17.50, 'mushroom ravioli (vegan)': 13.50, 'coffee': 1.50, 'espresso': 3.00,
early_bird_menu = Menu('Early_bird', early_bird_items, 1500, 1800 )

dinner_items = {
  'crostini with eggplant caponata': 13.00, 'ceaser salad': 16.00, 'pizza with quattro formaggi': 11.00, 'duck ragu': 19.50, 'mushroom ravioli (vegan)': 13.50, 'coffee': 2.00, 'espresso': 3.00 }

dinner_menu = Menu('Dinner', dinner_items, 1700, 2300)
purchase_one = [ 'pancakes', 'home fries', 'coffee' ]
# print(purchase_one)
sale_made = brunch_menu.calculate_bill(purchase_one)
purchase_two = ['salumeria plate', ' mushroom ravioli (vegan)']
# print(purchase_two)
sale_made2 = early_bird_menu.calculate_bill(purchase_two)

I welcome your suggestions.

if you print out all the steps you’re carrying out you’ll be able to spot which particular operation is having a result other than what you expected and then you can look closer at the inputs and outputs involved in that

printing all of it might be a bit overkill but I’m not sure how to put into words what you’d choose. the point is that it’s all observable.

you already have commented out prints in there so you already had the idea. did you give up? maybe what you needed to be looking at happened at an earlier or later time, so you’d continue looking there.

Hi @ionatan,
edited see end
I’m still puzzled, that I can get the correct results when I run this code from within my local python environment using geany, but here it does not. Does this mean that my local system is missing an error during execution? thanks for your reply. I’ll work on observing what this error is.

ooops I found it. extra space in a field caused the logic to miss the second menu item.

The output of your code is:


If you’re getting something else you’re running something else.

And yeah there’s an extra space. Which is trivial, but being trivial is beside the point. The point is you should be able to get in there and find the difference regardless, by observing and narrowing down. Obviously that’s harder if you’re not feeling entirely in control of the environments you’re running it in, makes it easy to accidentally have different versions and such.

So a good start is to make sure that you’re able to reproduce the problem, and once you have that you can go chasing after it.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.