Skip to content

Commit e4c5a98

Browse files
authored
Merge pull request #32 from code-for-tomorrow/Citrus716-patch-3
Added cashier_job solution and practice template
2 parents 4300b16 + 5994bc4 commit e4c5a98

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.
6+
#
7+
# Print what is returned by the function after it is run with 97 pennies,
8+
# 13 nickels, 18 dimes, 54 quarters, and 20% discount.
9+
# Print what is returned by the function after it is run with 32 pennies,
10+
# 19 nickels, 22 dimes, 71 quarters, and 51% discount.
11+
12+
# write code here
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.
6+
#
7+
# Print what is returned by the function after it is run with 97 pennies,
8+
# 13 nickels, 18 dimes, 54 quarters, and 20% discount.
9+
# Print what is returned by the function after it is run with 32 pennies,
10+
# 19 nickels, 22 dimes, 71 quarters, and 51% discount.
11+
12+
13+
def calculate_total(penny, nickel, dime, quarter, discount):
14+
before_discount = (
15+
0.01 * penny + 0.05 * nickel + 0.1 * dime + 0.25 * quarter
16+
)
17+
discount_multiplier = 1 - discount * 0.01
18+
19+
# Round to 2 decimals since it is money
20+
return round(before_discount * discount_multiplier, 2)
21+
22+
23+
print(calculate_total(97, 13, 18, 54, 20))
24+
25+
print(calculate_total(32, 19, 22, 71, 51))

0 commit comments

Comments
 (0)