cig-cost/cost-of-smokes.py

47 lines
1.1 KiB
Python
Raw Normal View History

2020-08-17 12:20:51 -04:00
#!/usr/bin/python3
#user input dolloars
#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
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-08-17 12:40:41 -04:00
os.system('clear')
2020-08-17 12:20:51 -04:00
break
2020-08-17 12:40:41 -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 16:36:56 -04:00
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")
2020-08-17 12:20:51 -04:00