Back to Freecodecamp

Step 5

curriculum/challenges/english/blocks/workshop-bill-splitter/69779dcb44016eccc05c15a4.md

latest1.5 KB
Original Source

--description--

The service was excellent, so the group decides to leave a 25% tip. To calculate a percentage in Python, you can multiply the total by the decimal equivalent of the percentage.

For example, to find 10% of a value, you would multiply it by 0.10 using the * operator:

py
tax = total * 0.10

Create a variable named tip and assign it the result of multiplying running_total by 0.25.

Finally, use print() to display the string Tip amount: followed by a space and the value of your tip variable.

--hints--

You should have a variable named tip.

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

Your tip variable should be the result of running_total * 0.25.

js
({
    test: () => runPython(`
    t = _Node(_code).find_variable('tip')
    assert t.is_equivalent('tip = running_total * 0.25') or t.is_equivalent('tip = 0.25 * running_total')`)
})

You should print the string Tip amount: followed by a space and the tip variable.

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

--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)

--fcc-editable-region--

--fcc-editable-region--