Back to Freecodecamp

Step 6

curriculum/challenges/english/blocks/workshop-bill-splitter/6977a4306bb3e856690a4890.md

latest1.4 KB
Original Source

--description--

Now that you have calculated the tip, you need to add it to your running_total to find the final bill amount.

In Python, you can use the augmented assignment operator += to add a value to a variable and update that variable at the same time. For example, total += 5 is a shorthand way of writing total = total + 5.

Use the += operator to add the value of tip to your running_total. Finally, use print() to display the string Total with tip: followed by a space and the value of running_total.

--hints--

You should use the += operator to add the value of tip to your running_total.

js
({
    test: () => assert(runPython(`
    _Node(_code).has_stmt('running_total += tip')
    `))
})

You should print the string Total with tip: followed by a space and the running_total variable.

js
({
    test: () => assert(runPython(`
    _Node(_code).has_call("print('Total with tip:', running_total)") or _Node(_code).has_call("print(f'Total with tip: {running_total}')")`))
})

--seed--

--seed-contents--

py
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:', running_total)

tip = running_total * 0.25
print('Tip amount:', tip)

--fcc-editable-region--

--fcc-editable-region--