cig-cost/cost-of-smokes.py

72 lines
1.6 KiB
Python
Raw Normal View History

2020-08-17 12:20:51 -04:00
#!/usr/bin/python3
2020-09-17 23:23:36 -07:00
#user input dollars
2020-08-17 12:20:51 -04:00
#user input number of packs
#output day, week, month year costs
import os
2020-08-17 12:57:36 -04:00
import math
2020-08-17 12:20:51 -04:00
cost = None
packs = None
2020-09-14 17:08:38 -04:00
def calcHours(tempCost):
return format(float(tempCost)/wages, '.2f')
2020-08-17 12:20:51 -04:00
while True:
os.system('clear')
try:
cost = float(input("How much does a pack cost? "))
except ValueError:
print("Please only type numbers")
2020-08-17 12:35:10 -04:00
input("Press 'enter' to continue: ")
2020-08-17 12:20:51 -04:00
continue
try:
packs = float(input("How many packs do you smoke a day? "))
except ValueError:
print("Please only type numbers")
2020-08-17 12:35:10 -04:00
input("Press 'enter' to continue: ")
2020-08-17 12:20:51 -04:00
continue
2020-09-14 17:08:38 -04:00
try:
wages = float(input("What is your hourly wage? "))
except ValueError:
print("Please only type numbers")
input("Press 'enter' to continue: ")
continue
2020-08-17 12:40:41 -04:00
os.system('clear')
2020-08-17 12:20:51 -04:00
break
2020-09-14 17:08:38 -04:00
2020-09-14 16:36:56 -04:00
print("Your cigarettes cost $" + format(cost/20, '.2f'), "each")
2020-08-17 12:40:41 -04:00
2020-08-17 12:20:51 -04:00
print()
print("You smoke: ")
2020-08-17 12:57:36 -04:00
print(math.ceil(20 * packs), "per day")
print(math.ceil(20 * packs * 7), "per week")
print(math.ceil((20 * packs * 365)/12), "per month")
print(math.ceil(20 * packs * 365), "per year")
2020-08-17 12:57:36 -04:00
2020-08-17 12:20:51 -04:00
print()
2020-08-17 12:57:36 -04:00
2020-08-17 12:20:51 -04:00
print("This costs you: ")
2020-09-14 17:08:38 -04:00
tempCost = format(cost * packs, '.2f')
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per day")
tempCost = format(cost * packs * 7, '.2f')
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per week")
tempCost = format((cost * packs * 365)/12, '.2f')
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per month")
tempCost = format(cost * packs * 365, '.2f')
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per year")
2020-08-17 12:20:51 -04:00