Build a Bill Splitter - Step 4

Tell us what’s happening:

I don’t understand what it means by ‘You should update running_total using the += operator once to add all four course costs.’ It is saying this when I submit my code.

Your code so far

running_total = 0

num_of_friends = 4

appetizers = 37.89
main_courses = 57.34
desserts = 39.39
drinks = 64.21

# User Editable Region
running_total += 37.89 + 57.34 + 39.39 + 64.21
print('Total bill so far:')
print(running_total)
# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

Challenge Information:

Build a Bill Splitter - Step 4

GitHub Link: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/workshop-bill-splitter/6982684f3a25f379e195a5fc.md

Hi @swathi.kandimalla89,

Please use the variables, not the values stored in the variables.

Happy coding

I will see if that works

Hey @swathi.kandimalla89

Use the += operator once to add appetizers, main_courses, desserts, and drinks to running_total.

We already stored each cost in a variable with a meaningful name. So instead of repeating the raw numbers, we should reference those variables. You can think of variables like labeled boxes, such as, appetizers is a the box holding 37.89. Why write 37.89 again when you can just say appetizers?

appetizers = 37.89
main_courses = 57.34
desserts = 39.39
drinks = 64.21

Happy coding!

dhess that did not work

Can you share your updated code?

It does not work when I do that

running_total = 0

num_of_friends = 4

appetizers = 37.89
main_courses = 57.34
desserts = 39.39
drinks = 64.21

running_total += appetizers + main_courses + desserts + drinks
print('Total bill so far:')
print(running_total)

Finally, use print() to display the string Total bill so far: followed by a space and the value of running_total.

Make sure you follow the above instruction.

Thank you imsomilg for helping me :smiley:

So the challenge is specifically checking you use the variable names instead of hardcoding the numbers. Swap those out and you’re set.

That’s why you define those variables upfront—to use them in the calculation. Makes it way easier if a price changes and you only have to update one spot.