cig-cost/cost-of-smokes.py
2020-09-21 21:45:21 -07:00

74 lines
2.0 KiB
Python

#!/usr/bin/python3
#user input dollars
#user input number of packs
#output day, week, month year costs
import os
import math
import ciglib
from ciglib import fgColor
cost = None
packs = None
def calcHours(tempCost):
return format(float(tempCost)/wages, '.2f')
while True:
os.system('clear')
try:
cost = float(input("How much does a pack cost? "))
except ValueError:
print("Please only type numbers")
input("Press 'enter' to continue: ")
continue
try:
packs = float(input("How many packs do you smoke a day? "))
except ValueError:
print("Please only type numbers")
input("Press 'enter' to continue: ")
continue
try:
wages = float(input("What is your hourly wage? "))
except ValueError:
print("Please only type numbers")
input("Press 'enter' to continue: ")
continue
os.system('clear')
break
print(fgColor.RED,"Your cigarettes cost $" + format(cost/20, '.2f'), "each", fgColor.NC)
print()
print(fgColor.CYAN,"You smoke: ",fgColor.NC)
print(fgColor.YELLOW,math.ceil(20 * packs), "cigarettes per day", fgColor.NC)
print(fgColor.YELLOW,math.ceil(20 * packs * 7), "cigarettes per week",fgColor.NC)
print(fgColor.YELLOW,math.ceil((20 * packs * 365)/12), "cigarettes per month",fgColor.NC)
print(fgColor.YELLOW,math.ceil(20 * packs * 365), "cigarettes per year", fgColor.NC)
print()
print(fgColor.CYAN,"This costs you: ",fgColor.NC)
tempCost = format(cost * packs, '.2f')
tempHours = calcHours(tempCost)
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per day",fgColor.NC)
tempCost = format(cost * packs * 7, '.2f')
tempHours = calcHours(tempCost)
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per week",fgColor.NC)
tempCost = format((cost * packs * 365)/12, '.2f')
tempHours = calcHours(tempCost)
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per month",fgColor.NC)
tempCost = format(cost * packs * 365, '.2f')
tempHours = calcHours(tempCost)
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per year",fgColor.NC)