Untitled
unknown
plain_text
4 years ago
6.4 kB
5
Indexable
# Imports from time import sleep # Generating core data # Item list with open('shopping_item_list.txt') as item_name_data: item_list = item_name_data.readlines() for i in range(len(item_list)): if '\n' in item_list[i]: item_list[i] = item_list[i].replace('\n', '') # Item prices with open('item_prices.txt') as item_price_data: item_price = item_price_data.readlines() for i in range(len(item_price)): if '\n' in item_price[i]: item_price[i] = item_price[i].replace('\n', '') # Item info (UNDER CONSTRUCTION) item_info = [] temp_list = [] with open('item_info.txt') as item_info_data: for a in range(3): for b in range(5): temp_list.append(item_info_data.readline()) item_info.append(temp_list) temp_list.clear() # Cart shopping_cart = {} # Billing info billing_info = {} # Built-in functions def help(): print( ''' help(): show this help box. exit(): exit the program. WARMING: All items currently in cart will be lost, so please be careful. list(): list all available items. info(*item ID*): list all info of an item. search('keyword'): search for items by keywords (case-sensitive, keyword must be put in quotation marks or apostrophes). search_id(*item ID*): search for items by item ID. billinginfo(): list your payment info, or enter your payment info if none found. cart(): view your cart. add(*item ID*): add an item to your cart. remove(*item ID*): remove an item from your cart. checkout(): proceed to checkout. ''') def checkout_confirmation(): print() print("Your order and credentials are listed below:") print() cart() print() billinginfo() confirmation = input("Proceed to checkout? (Y/N)") if confirmation == 'Y' or confirmation == 'y': print("Your order has been placed, thank you for choosing us!") shopping_cart.clear() elif confirmation == 'N' or confirmation == 'n': print("Checkout cancelled.") else: print("Unknown command. Please try again below.") checkout_confirmation() def list(): for j in range(len(item_list)): print(f"{j}: {item_list[j]} - {item_price[j]}$") def search(name): products_found = 0 try: for k in range(len(item_list)): if name in item_list[k]: print(f"{k}: {item_list[k]} - {item_price[k]}$") products_found += 1 print(f"Found {products_found} items.") except: print("ERROR: Expression is not a string.") def search_id(ID): try: print(f"{ID}: {item_list[ID]} - {item_price[ID]}$") except: print("ERROR: No such item found or bad ID.") def billinginfo(): billinginfo_placeholders = ['Name (as shown on credit card)', 'Card Type(Visa/Mastercard)', 'Credit Card Number', 'CVV', 'Expiry Date', 'Billing Address'] if len(billing_info) == 0: for l in range(len(billinginfo_placeholders)): billing_info[billinginfo_placeholders[l]] = input(f"{billinginfo_placeholders[l]}: ") else: for key, value in billing_info.items(): print(f"{key}: {value}") def cart(): total_price = 0 if len(shopping_cart) == 0: print("Cart is empty.") else: for item in shopping_cart: print(f"{item}: {shopping_cart[item]} - {item_price[item]}$") total_price += int(item_price[item]) print(f"Total: {total_price}$") def add(ID): try: shopping_cart.update({ID: item_list[ID]}) print(f"Successfully added {ID} - {item_list[ID]} to cart.") except: print("ERROR: No such item found.") def remove(ID): try: shopping_cart.pop(ID) print(f"Successfully removed {ID} - {item_list[ID]} from cart.") except: print("ERROR: No such item in cart.") def checkout(): if len(shopping_cart) == 0: print("Cart is empty, cannot proceed to checkout.") else: if len(billing_info) == 0: print("It seems like you currently don't have payment info, please type in your credentials as prompted below.") billinginfo() checkout_confirmation() else: checkout_confirmation() # Main program # Welcome screen print( ''' _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | | | ___________.__ ________ /\ | | \__ ___/| |__ ____ / _____/_____ _____ ___________ _____)/ | | | | | | \_/ __ \ / \ ___\__ \ / \_/ __ \_ __ \/ ___/ | | | | | Y \ ___/ \ \_\ \/ __ \| Y Y \ ___/| | \/\___ \ | | |____| |___| /\___ > \______ (____ /__|_| /\___ >__| /____ > | | \/ \/ \/ \/ \/ \/ \/ | | _________ | | \_ ___ \ ___________ ____ ___________ | | / \ \/ / _ \_ __ \/ \_/ __ \_ __ \ | | \ \___( <_> ) | \/ | \ ___/| | \/ | | \______ /\____/|__| |___| /\___ >__| | | \/ \/ \/ | | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | Welcome to The Gamers' Corner, an online shop dedicated to gaming hardware and devices. Start typing functions to shop. To get a list of available functions, type "help()". We only accept Credit Card. ''' ) # Taking user inputs and executing the commands while True: user_input = input() if user_input != 'exit()': try: eval(user_input) except: print("ERROR: Unexpected command or expression.") print() else: print('Thank you for visiting The Gamers Corner! Have a good gaming day!') for timeout in range(3, 0, -1): print(f"Terminating current session in {timeout}...", end='\r') sleep(1) exit()
Editor is loading...