-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMealTotalCalculator.py
More file actions
28 lines (23 loc) · 904 Bytes
/
MealTotalCalculator.py
File metadata and controls
28 lines (23 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import math
import sys
# Take price input from customer.
charge_for_food = float(input("Enter the charge for the food.\n"))
if(charge_for_food <= 0):
print("Please enter a valid charge.")
sys.exit()
sales_tax_percentage = 7
tip_percentage = 18
# Calculate the tax, tip and the total. Ceiling the values and capping to two decimal places.
sales_tax = math.ceil(100 * charge_for_food * (1 + sales_tax_percentage / 100)) / 100
tip = math.ceil(100 * charge_for_food * ( 1 + tip_percentage / 100)) / 100
total = charge_for_food + sales_tax + tip
# Printing in formatted string to have appropriate spacing.
print("\n")
print(f"{"":-<40}")
print(f"{"Food price":<33} {charge_for_food:.2f}")
print(f"{sales_tax_percentage}% {"Sales tax":<30} {sales_tax:.2f}")
print(f"{tip_percentage}% {"Tip":<29} {tip:.2f}")
print(f"{"":-<40}")
print(f"{"Total":<33} {total:.2f}")
print(f"{"":-<40}")
print("\n")