CNSA-266-Personal/Skateboards.py

99 lines
2.8 KiB
Python
Raw Normal View History

2024-04-23 09:40:13 -04:00
import time
# Item Prices
YELLOW_COST = 15.97
BLUE_COST = 24.99
# Summary Values
totalYellow = 0
totalBlue = 0
TotalTransactions = 0
TotalSales = 0.0
# Tax Rates
IN_TAX = 0.04
OUT_TAX = 0.06
repeat = True
print("\n"*100)
print("Welcome to TSCT Skating Association!\n")
# Keep looping until user decides to exit
while repeat:
state = "z"
sale = 0.0
# Get number of blue skateboards
blue = input("How many blue skateboards ($24.99) would you like to purchase: ")
if blue.isnumeric():
blue = int(blue)
else:
blue = 0
# Get number of yellow skateboards
yellow = input("How many yellow skateboards ($15.97) would you like to purchase: ")
if yellow.isnumeric():
yellow = int(yellow)
else:
yellow = 0
# Get whether the user is from out of state or not for use with tax rates
while True:
state = input("Are you from out of state? (y/n): ")
if state == "y" or state == "Y" or state == "n" or state == "N":
break
else:
print("Please enter either 'y' or 'n'.")
# set tax rates
if state == "y" or state == "Y":
tax = OUT_TAX
else:
tax = IN_TAX
# Calculate this sale
sale = round((blue * BLUE_COST + yellow * YELLOW_COST) * (1+tax),2)
# Update running totals
totalYellow += yellow
totalBlue += blue
TotalTransactions += 1
TotalSales += sale
# Print out the sale
print("You sold " + str(format(blue, ',')) + " blue skateboards, and " + str(format(yellow, ',')) + " yellow skateboards.")
print("This will cost $" + str(format(sale, ',.2f')), end="\n\n")
# ask the user if they would like to make another sale
while True:
again = input("Would you like to make another sale? (y/n): ")
if again == "y" or again == "Y":
print("Initiating a new sale.",end="")
time.sleep(0.5)
print(".",end="")
time.sleep(0.5)
print(".",end="")
time.sleep(0.5)
print("\n"*100)
break
elif again == "n" or again == "N":
print("Exiting.",end="")
time.sleep(0.5)
print(".",end="")
time.sleep(0.5)
print(".",end="")
time.sleep(0.5)
print("\n"*100)
repeat = False
break
else:
print("Please enter either 'y' or 'n'.")
# Print out the summary
print("You sold " + str(format(totalBlue,',')) + " blue skateboards, and " + str(format(totalYellow,',')) + " yellow skateboards.")
print("You made a total of " + str(format(TotalTransactions,',')) + " individual transactions.")
print("You made $" + str(format(round(TotalSales,2),',.2f')), end=".\n\n")
print("Thank you for using TSCT Skating Association!")