|
1 | | -# Write a function that will take the number of pennies, nickels, dimes, |
2 | | -# quarters, and discount(i.e. 15 for 15% discount). Return the total amount of |
3 | | -# money after discount. |
| 1 | +# Cashier Job |
| 2 | +# Write a function called calculate_total |
| 3 | +# that will take the number of pennies, nickels, dimes, |
| 4 | +# quarters, and discount rate (i.e. 15 for 15% discount). |
| 5 | +# Return the total amount of money after discount. |
4 | 6 | # |
5 | 7 | # Print what is returned by the function after it is run with 97 pennies, |
6 | 8 | # 13 nickels, 18 dimes, 54 quarters, and 20% discount. |
7 | 9 | # Print what is returned by the function after it is run with 32 pennies, |
8 | 10 | # 19 nickels, 22 dimes, 71 quarters, and 51% discount. |
9 | 11 |
|
10 | 12 |
|
11 | | -def calc_total(penny, nickel, dime, quarter, discount): |
| 13 | +def calculate_total(penny, nickel, dime, quarter, discount): |
12 | 14 | before_discount = ( |
13 | 15 | 0.01 * penny + 0.05 * nickel + 0.1 * dime + 0.25 * quarter |
14 | 16 | ) |
15 | 17 | discount_multiplier = 1 - discount * 0.01 |
16 | 18 |
|
| 19 | + # Round to 2 decimals since it is money |
17 | 20 | return round(before_discount * discount_multiplier, 2) |
18 | 21 |
|
19 | 22 |
|
20 | | -print(calc_total(97, 13, 18, 54, 20)) |
| 23 | +print(calculate_total(97, 13, 18, 54, 20)) |
21 | 24 |
|
22 | | -print(calc_total(32, 19, 22, 71, 51)) |
| 25 | +print(calculate_total(32, 19, 22, 71, 51)) |
0 commit comments