coffee_order.py
#!/bin/python3
#
#
#
#
# variables
#——————————
state_list = [ "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY", "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming" ]
# Functions
#——————————-
#
#
# Tax
# Tax Rate is 9% for Washington, California and Texas,
# 0% for Oregon or Florida, all other are 7%
#
def tax(shipping_location):
location = shipping_location.lower()
if location == 'wa' or location == 'washington' or location == 'tx' or location == 'texas' or location == 'ca' or location == 'california':
tax_rate = .09
return tax_rate
elif location == 'or' or location == 'oregon' or location == 'fl' or location == 'florida':
tax_rate = .00
return tax_rate
else:
tax_rate = .07
return tax_rate
# Shipping & Handling
# Overnight ($20.00), 2-Day ($13.00), Standard ($0.00).
def delivery_fee(delivery):
if delivery == 1:
return 20.00
elif delivery == 2:
return 13.00
elif delivery == 3:
return 00.00
else:
return 0
# subtotal
# or Payment options, Paypal has a 3% fee (of the Sub-Total),
# Credit Cards has a 5% fee (of the Sub-Total)
def subtotal():
sub = float(format((cost * lbs), '0.2f'))
return sub
# script sequence
#—————————————
print()
print("=======================================")
print(" Lono's Coffee Hut")
print("=======================================")
# Enter brand of coffee
while True:
try:
print("Please select one of our premier beans:")
print("1) Beacon Hill Brew $ 10.50 / pound")
print("2) Sammamish sunset $ 16.95 / pound")
print()
print()
coffee_type = int(input("Please enter type of coffee(1 or 2): "))
if coffee_type == 1:
print()
print()
brew = "Beacon Hill Brew"
cost = 10.50
break
elif coffee_type == 2:
print()
print()
brew = "Sammamish sunset"
cost = 16.95
break
except ValueError:
print()
print("Please enter a valid option")
print("Example: 1 or 2")
print()
continue
# Enter pounds of coffee
while True:
try:
lbs = float(input("Please enter amount of Delicious \nCoffee(in pounds to the hundreth, \nexample \"1.67\": "))
weight = format(lbs, '0.2f')
print()
print()
break
except ValueError:
print()
print("Please enter a number")
print("Example: 1.87")
print()
continue
# Enter shipping location state
while True:
print("Please enter the State this will ship \ntoo by name or postal abbriviation.")
print('For a list of states type "help"')
state = str(input("(Example: Washington or WA.): "))
print()
if state in state_list:
break
if state.upper() in state_list:
break
if state.capitalize() in state_list:
break
elif state == "help":
print(" State and postal code list")
print("==============================================")
print(state_list)
print("==============================================")
print()
print()
continue
else:
print("Invalid input. Please try again.")
continue
# Delivery Options
#
# delivery methods are Overnight ($20.00), 2-Day ($13.00),
# Standard ($0.00)
#
while True:
try:
print("Delivery Options:")
print()
print("1) Standard")
print("2) 2-day")
print("3) Overnight")
delivery_type = int(input("Please enter number of the delivery option(1, 2, or 3): "))
if delivery_type == 1:
print()
print()
delivery = "Standard(FREE SHIPPING)"
delivery_cost = 0.00
break
elif delivery_type == 2:
print()
print()
delivery = "2-day($13.00)"
delivery_cost = 13.00
break
elif delivery_type == 3:
print()
print()
delivery = "Overnight($20.00)"
delivery_cost = 20.00
break
except ValueError:
print()
print("Please enter a valid option")
print("Example: 1 or 2 or 3")
print()
continue
# Enter Payment Type
#
# Payment options, Paypal has a 3% fee (of the Sub-Total), Credit Cards has a 5%
# fee (of the Sub-Total) and Checks have a 2% discount
while True:
try:
print("Payment Options:")
print()
print("1) Paypal(3% fee)")
print("2) Credit Card(5% fee)")
print("3) Check(2% Discount)")
print("4) Cash Money")
payment_type = int(input("Please enter number of the payment option(1, 2, or 3): "))
if payment_type == 1:
print()
print()
payment = "paypal"
payment_adj = 0.03
break
elif payment_type == 2:
print()
print()
payment = "credit"
payment_adj = 0.05
break
elif payment_type == 3:
print()
print()
payment = "check"
payment_adj = -0.02
break
elif payment_type == 4:
print()
print()
payment = "cash"
payment_adj = 0.00
break
except ValueError:
print()
print("Please enter a valid option")
print("Example: 1 or 2")
print()
continue
# Float var to the second decimal
tax_rounded = float(format((subtotal() * tax(state)), '0.2f'))
surcharge_rounded = float(format((subtotal() * payment_adj), '0.2f'))
#delivery_cost_formatted = float(format(delivery_cost, '0.2f'))
#total_bill = float(format(delivery_cost_formatted + subtotal() + surcharge_rounded + tax_rounded, '0.2f'))
# String var for easy printing
tx_fmt = format((subtotal() * tax(state)), '0.2f')
sur = format((subtotal() * payment_adj), '0.2f')
deliv = format(delivery_cost, '0.2f')
tot_fmt = format(delivery_cost + subtotal() + surcharge_rounded + tax_rounded, '0.2f')
sub_fmt = format(subtotal() + (subtotal() * payment_adj), '0.2f')
print("surcharge string test: ",sur)
print("delivery string test: ",deliv)
print("total", tot_fmt)
print()
print("==============================================")
print(" Lono's Coffee Hut Order Information ")
print("==============================================")
print()
print("Roast: ", brew)
print("Quanity: ",weight,".lbs")
print("Payment Method: ", payment)
print("payment surcharge: ${}".format(sur), "(Included in Subtotal)")
print("shipping option: ", delivery)
print("———————————————-")
print()
print("Sub Total: ${}".format(sub_fmt))
print("Delivery Fee: ${}".format(deliv))
print("Tax({}%): ${}".format(tax(state), tx_fmt))
print("—————————–")
print("Total: ${}".format(tot_fmt))
print()
print("=============================================")
print()
print()
No Comments
RSS feed for comments on this post.
Sorry, the comment form is closed at this time.