Skip to content

Instantly share code, notes, and snippets.

@ryeounhoward
Last active October 10, 2025 15:07
Show Gist options
  • Select an option

  • Save ryeounhoward/cdada2832f33531c46ba64cc0035e8aa to your computer and use it in GitHub Desktop.

Select an option

Save ryeounhoward/cdada2832f33531c46ba64cc0035e8aa to your computer and use it in GitHub Desktop.
items = ["apple", "banana", "milk", "bread"]
prices = [20, 15, 50, 35]
total = 0
while True:
print("===========Welcome to the Grocery Store!===========")
print(f"TYPE OF CUSTOMER:\n1: PWD\n2: Senior Citizen\n3: Regular Customer")
while True:
type_of_customer = int(input("Enter type of customer (1-3): "))
if type_of_customer in [1, 2, 3]:
break
print("Invalid input. Please enter 1, 2, or 3.")
print(f"\nMaximum items you can buy is {len(items)}.")
while True:
num_items = int(input("How many different items do you want to buy? "))
if 1 <= num_items <= len(items):
break
print(f"Please enter a number between 1 and {len(items)}.")
print("\nAvailable items and their prices:")
for x in items:
print(f"{x}: {prices[items.index(x)]}")
for i in range(num_items):
while True:
item = input(f"\nEnter item name #{i+1}: ").lower()
if item in items:
break
print("Item not found. Please enter a valid item name.")
while True:
try:
qty = int(input(f"Enter quantity of {item}: "))
if qty > 0:
break
print("Quantity must be greater than 0.")
except ValueError:
print("Please enter a valid number.")
index = items.index(item)
subtotal = prices[index] * qty
total += subtotal
print(f"\nTotal before discount: {total}")
if total >= 200 and type_of_customer in [1, 2]:
discount = total * 0.10
total -= discount
print("Discount applied: ", discount)
else:
print("No discount applied")
methods = {1: "Gcash", 2: "Google Pay", 3: "Paymaya", 4: "Cash"}
payment_method = int(input(f"\nPAYMENT METHOD:\n1: {methods[1]}\n2: {methods[2]}\n3: {methods[3]}\n4: {methods[4]}\nEnter payment method (1-4): "))
match payment_method:
case 1 | 2 | 3:
print(f"You paid {total} via {methods[payment_method]}")
case 4:
while True:
cash = int(input("Enter cash amount: "))
if cash >= total:
change = cash - total
print(f"Your change is: {change}")
break
print("Insufficient cash. Please enter an amount greater than or equal to the total.")
print("\nThank you for shopping with us!")
buy_again = int(input("\nDo you want to buy again? (1: Yes, 2: No): "))
if buy_again != 1:
print("===========Goodbye and come again soon!===========")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment