cig-cost/cost-of-smokes.py

74 lines
1.7 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-09-19 10:08:37 -04:00
cigsPerPacks = math.ceil(20 * packs)
2020-09-19 09:56:31 -04:00
costPerPacks = cost * packs
YEAR=365
WEEK=7
2020-08-17 12:20:51 -04:00
print()
print("You smoke: ")
2020-09-19 10:08:37 -04:00
print(cigsPerPacks, "per day")
print(cigsPerPacks * WEEK, "per week")
2020-09-19 09:56:31 -04:00
print(math.ceil((cigsPerPacks * YEAR)/12), "per month")
2020-09-19 10:08:37 -04:00
print(cigsPerPacks * YEAR, "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
2020-09-19 09:56:31 -04:00
tempCost = format(costPerPacks, '.2f')
2020-09-14 17:08:38 -04:00
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per day")
2020-09-19 09:56:31 -04:00
tempCost = format(costPerPacks * WEEK, '.2f')
2020-09-14 17:08:38 -04:00
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per week")
2020-09-19 09:56:31 -04:00
tempCost = format((costPerPacks * YEAR)/12, '.2f')
2020-09-14 17:08:38 -04:00
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per month")
2020-09-19 09:56:31 -04:00
tempCost = format(costPerPacks * YEAR, '.2f')
2020-09-14 17:08:38 -04:00
tempHours = calcHours(tempCost)
print("$" + tempCost, "and", tempHours, "hours per year")