diff --git a/cost-of-smokes.py b/cost-of-smokes.py index cce6c5e..f2913c4 100644 --- a/cost-of-smokes.py +++ b/cost-of-smokes.py @@ -8,6 +8,12 @@ import math cost = None packs = None + +def calcHours(tempCost): + return format(float(tempCost)/wages, '.2f') + + + while True: os.system('clear') try: @@ -23,10 +29,17 @@ while True: 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("Your cigarettes cost $" + format(cost/20, '.2f'), "each") print() @@ -39,8 +52,20 @@ print(math.ceil(20 * packs * 365), "per year") print() print("This costs you: ") -print("$" + format(cost * packs, '.2f'), "Per day") -print("$" + format(cost * packs * 7, '.2f'), "per week") -print("$" + format((cost * packs * 365)/12, '.2f'), "per month") -print("$" + format(cost * packs * 365, '.2f'), "per year") + +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")