-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalculator.py
More file actions
147 lines (115 loc) · 5.45 KB
/
calculator.py
File metadata and controls
147 lines (115 loc) · 5.45 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
__author__ = 'Chris'
print("Welcome to the formula calculator.")
print("KEY:")
print("MPG ------ Calculate miles per gallon.")
print("KINETIC -- Calculate an object's kinetic energy.")
print("PAY -------Calculate pay for hours worked.")
print("FTM -------Convert feet to meters.")
print("YIELD -----Calculate labor yield.")
print("PERCENT ---Calculate labor percent.")
print("PROFIT ----Calculate profits given sales, cost of labor, and cost of sales.")
print("QUIT ------Close the calculator.")
# Calculate MPG taking in miles driven and gallons of fuel used
def mileage(miles_driven, gallons_used):
mpg = float(miles_driven / gallons_used)
return mpg
# Calculate kinetic energy (mass in kilograms, velocity in meters per second)
def kineteic_energy(mass, velocity):
e = 0.5 * mass * velocity * velocity
return e
# Calculate pay
def pay(hours, wage):
if hours > 40:
money = ((hours - 40) * wage * 1.5) + (40 * wage)
return money
else:
money = hours * wage
return money
# Convert feet to meters
def feet_to_meters(feet):
meters = feet / 3.2808
return meters
# Calculate labor yield (amount of money made per hour of labor used)
def labor_yield(sales, hours_used):
lyield = float(sales / hours_used)
return lyield
# Calculate labor percentage (percentage of sales that went to labor cost)
def labor_percent(sales, pay_used):
percent = float((pay_used / sales) * 100)
return percent
# Calculate profits
def profit(sales, pay_used, cost_sales):
gain = float(sales - pay_used - cost_sales)
return gain
# Allow user to choose which calculation they would like to perform
while True:
print(" ")
print(" ")
choice = (input("What would you like me to calculate? Or type 'quit' to quit." + "\n>>>")).upper()
if choice == "MPG":
try:
traveled = float(input("How many miles were traveled?"))
fuel = float(input("How many gallons of fuel were used?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
miles_per_gallon = mileage(traveled, fuel)
print("After traveling " + str(traveled) + " miles and using " + str(fuel) + " gallons of fuel. Your MPG was " + str(miles_per_gallon))
elif choice == "KINETIC":
try:
weight = float(input("How much does the object weight (in kilograms)?"))
speed = float(input("What is the speed of the object (in meters per second)?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
energy = kineteic_energy(weight, speed)
print("The kinetic energy of an object weighing " + str(weight) + " kilograms and moving " + str(speed) + " meters per second is " + str(energy) + " joules.")
elif choice == "PAY":
try:
hours_worked = float(input("How many hours were worked?"))
pay_rate = float(input("What is the pay rate per hour?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
pay_check = pay(hours_worked, pay_rate)
print("Working for " + str(hours_worked) + " hours at " + str(pay_rate) + " per hour. Your pay is " + str(pay_check) + " dollars.")
elif choice == "FTM":
try:
foot = float(input("How many feet would would you like to convert?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
meter = feet_to_meters(foot)
print(str(foot) + " feet is " + str(meter) + " meters.")
elif choice == "YIELD":
try:
sales = float(input("How much is money was brought in(sales)?"))
hours = float(input("How many labor hours were used?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
labor_y = labor_yield(sales, hours)
print("For " + str(sales) + " in sales and " + str(hours) + " hours of labor used, labor yield is " + str(labor_y) + " dollars.")
choose()
elif choice == "PERCENT":
try:
sales = float(input("How much money was brought in(sales)?"))
payroll = float(input("How much money was spent on labor?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
print("For " + str(sales) + " dollars in sales and " + str(payroll) + " dollars spent on labor, labor is " + str(labor_percent(sales, payroll)) + " percent.")
elif choice == "PROFIT":
try:
sales = float(input("How much money was brought in(sales)?"))
payroll = float(input("How much money was spent on labor?"))
cost_of_sales = float(input("How much did the merchandise cost?"))
except ValueError:
print("OOPS! That wasn't a number!")
continue
profits = profit(sales, payroll, cost_of_sales)
print("For " + str(sales) + " dollars in sales, " + str(payroll) + " dollars spent on labor and " + str(cost_of_sales) + " dollars spent on merchandise, profits are " + str(profits) + " dollars.")
elif choice == "QUIT":
quit()
else:
print("I don't know that calculation, please try again.")