Hello all,
I am in chapter 5 of Automate the Boring Stuff with Python and working on coding the guest list problem in the chapter. For reference, I am using mu-editor with my coding stuff. I keep getting a syntax error for the def totalBrought (line 3) and cannot for the life of me figure out what I did wrong. I am including an the code below for reference. Please keep in mind I am a SUPER newb so I'm sure I am overlooking something super easy and simple. Any help or guidance would be much appreciated!
allGuests={'Alice': {'apples':5, 'pretzels': 12}, {'Bob':{'ham sammies': 3, 'apples':2}, 'Carol': {'cups': 3, 'apple pies':1}}
def totalBrought(guests,item):
numBrought=0
for k, v in guests.items():
numBrought=numBrought+v.get(item,0)
return numBrought
print('Number of things being brought:')
print('-Apples '+str(totalBrought(allGuests, 'apples')))
print(' -Cups '+str(totalBrought(allGuests, 'cups')))
print(' -Cakes '+str(totalBrought(allGuests, 'cakes')))
print(' -Ham Sammies '+str(totalBrought(allGuests, 'ham sammies')))
print(' -Apple pies '+str(totalBrought(allGuests, 'apple pies')))
Here's the output I am getting:
def totalBrought(guests,item):
^
SyntaxError: invalid syntax
Thank you!
I am in chapter 5 of Automate the Boring Stuff with Python and working on coding the guest list problem in the chapter. For reference, I am using mu-editor with my coding stuff. I keep getting a syntax error for the def totalBrought (line 3) and cannot for the life of me figure out what I did wrong. I am including an the code below for reference. Please keep in mind I am a SUPER newb so I'm sure I am overlooking something super easy and simple. Any help or guidance would be much appreciated!
allGuests={'Alice': {'apples':5, 'pretzels': 12}, {'Bob':{'ham sammies': 3, 'apples':2}, 'Carol': {'cups': 3, 'apple pies':1}}
def totalBrought(guests,item):
numBrought=0
for k, v in guests.items():
numBrought=numBrought+v.get(item,0)
return numBrought
print('Number of things being brought:')
print('-Apples '+str(totalBrought(allGuests, 'apples')))
print(' -Cups '+str(totalBrought(allGuests, 'cups')))
print(' -Cakes '+str(totalBrought(allGuests, 'cakes')))
print(' -Ham Sammies '+str(totalBrought(allGuests, 'ham sammies')))
print(' -Apple pies '+str(totalBrought(allGuests, 'apple pies')))
Here's the output I am getting:
def totalBrought(guests,item):
^
SyntaxError: invalid syntax
Thank you!