mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 10:22:16 +00:00
fix(curriculum): remove repetitive explanations in bill splitter workshop (#67081)
This commit is contained in:
+1
-7
@@ -9,13 +9,7 @@ dashedName: step-1
|
||||
|
||||
In this workshop, you will practice working with numbers and mathematical operations to build a bill splitter. This tool will calculate how much each person owes after adding meal costs and a tip.
|
||||
|
||||
To start, you need a way to keep track of the total amount as costs are added. In Python, you can use a variable to store an integer (a whole number) that changes over time.
|
||||
|
||||
For example, you might write:
|
||||
|
||||
```py
|
||||
my_number = 2
|
||||
```
|
||||
To start, you need a way to keep track of the total amount as costs are added.
|
||||
|
||||
Create a variable named `running_total` and assign it the value `0`.
|
||||
|
||||
|
||||
-2
@@ -9,8 +9,6 @@ dashedName: step-6
|
||||
|
||||
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--
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ dashedName: step-8
|
||||
|
||||
The bill is split, but division often results in long decimal numbers. Since money is typically represented with two decimal places, you should round the final result.
|
||||
|
||||
Python provides a built-in `round()` function for this. It takes two arguments: the number you want to round and the number of decimal places to keep. Here's an example:
|
||||
In an earlier lesson, you learned about the `round()` function which takes two arguments: the number you want to round and the number of decimal places to keep. Here's an example:
|
||||
|
||||
```py
|
||||
num = 4.815162342
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@ dashedName: step-4
|
||||
|
||||
# --description--
|
||||
|
||||
Now that you have stored the individual costs, you can calculate the total. In Python, you use the addition operator `+` to sum values together.
|
||||
Now that you have stored the individual costs, you can calculate the total.
|
||||
|
||||
The `+=` operator adds a value to an existing variable and updates it at the same time. For example:
|
||||
Recall that the `+=` operator adds a value to an existing variable and updates it at the same time. For example:
|
||||
|
||||
```py
|
||||
total = 10
|
||||
|
||||
Reference in New Issue
Block a user