cig-cost/cost-of-smokes.py

74 lines
2.0 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-09-21 21:45:21 -07:00
import ciglib
from ciglib import fgColor
2020-08-17 12:57:36 -04:00
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-21 21:45:21 -07:00
print(fgColor.RED,"Your cigarettes cost $" + format(cost/20, '.2f'), "each", fgColor.NC)
2020-08-17 12:40:41 -04:00
2020-08-17 12:20:51 -04:00
print()
2020-09-21 21:45:21 -07:00
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)
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-09-21 21:45:21 -07:00
print(fgColor.CYAN,"This costs you: ",fgColor.NC)
2020-09-14 17:08:38 -04:00
tempCost = format(cost * packs, '.2f')
tempHours = calcHours(tempCost)
2020-09-21 21:45:21 -07:00
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per day",fgColor.NC)
2020-09-14 17:08:38 -04:00
tempCost = format(cost * packs * 7, '.2f')
tempHours = calcHours(tempCost)
2020-09-21 21:45:21 -07:00
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per week",fgColor.NC)
2020-09-14 17:08:38 -04:00
tempCost = format((cost * packs * 365)/12, '.2f')
tempHours = calcHours(tempCost)
2020-09-21 21:45:21 -07:00
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per month",fgColor.NC)
2020-09-14 17:08:38 -04:00
tempCost = format(cost * packs * 365, '.2f')
tempHours = calcHours(tempCost)
2020-09-21 21:45:21 -07:00
print(fgColor.GREEN,"$" + tempCost, "and", tempHours, "work hours per year",fgColor.NC)
2020-08-17 12:20:51 -04:00