import locale locale.setlocale(locale.LC_ALL, '') order_total = 0.0 # accumulate total dollars price = 3.5 # all cookies are $3.50 per box fmt_price = locale.currency(price, grouping=True) # Define Cookie list. cookie_list = [] cookie_list = "Savanna Thin-mints Tag-a-Longs Peanut-Butter Sandwich".split() order_list = [] # Display cookie Choices def disp_items(): print("Please choose a flavor, Enter item number of choice") for c in range(len(cookie_list)): print("{}.\t{}".format(c+1, cookie_list[c])) print() # Define Funtions def calc_tot(qty): return qty * 3.5 def print_order(): fmt_total = locale.currency(item_total, grouping=True) print("order for {}".format(customer)) print() print("Total Items = {}".format(item_cnt)) print("Total Boxes = {}".format(qty)) print("Total Cost = ${}".format(item_total)) def disp_menu(): choice_list = ["a", "d", "m", "q"] while True: print("\nWhat would you like to do?") print("a = add an item") print("d = delete an item") print("m = display meal so far") print("q = quit") choice = input("\nmake a selection>") if choice in choice_list: return choice else: print("I do not understand that entry. Try again.") def add_process(): valid_data = False while not valid_data: # capture user cookie choice disp_items() try: item = int(input("enter item number>")) if 1 <= item <= len(cookie_list): valid_data = True else: print("\nThat was not a valid choice, please try again.") except Exception as detail: print("error: ", detail) # validate quantaty valid_data = False # reset boolean flag while not valid_data: try: qty = int(input("enter quantity>")) if 1 <= qty <= 10: valid_data = True else: print("\nThat was not a valid quantity, please try again.") except Exception as detail: print("error: ", detail) print("please try again") #stays in loop item_total = calc_tot(qty) fmt_total = locale.currency(item_total, grouping=True) # display user choice print("\nYou choose: {} boxes of {} for a total of {}".format(qty, cookie_list[item-1], fmt_total)) print() # verify inclusion of this item valid_data = False while not valid_data: incl = input("would you like to add this to your order? (y/n)>") print() if incl.lower() == "y": inx = item -1 detail_list = [inx, qty] order_list.append(detail_list) valid_data = True print("{} was added to your order".format(cookie_list[inx])) elif incl.lower() == "n": print("{} was not added to your order".format(cookie_list[inx])) valid_data = True else: print("that was not a valid response, please try again") def del_item(): if len(order_list) == 0: print("\nyou have no items in your oder to delete\n") else: print("\nDelete an Item") disp_order() valid_data = False while not valid_data: try: choice = int(input("please enter the item number you would like to delete>")) if 1 <= choice <= len(order_list): choice = choice -1 print("\nItem {}. {} with {} boxes will be deleted".format(choice + 1, order_list[choice][0], order_list[choice][1]) del order_list[choice] valid_data = True except Exception as detail: print("error: ", detail) print("please try again") # banner print("Welcome to the Girl Scout Cookie") print("Order Program") cust = input("\Please enter your name> ") while True: choice = disp_menu() if choice == "a": add_process() elif choice == "d": del_item() elif choice == "q": break # unconditionally display the order disp_order() disp_order() print("Thank you for your order")This is my program for school, girl scout cookie order form. Its meant to be able to add items into a order and remove when needed. I get an error code "Invalid syntax" for line 153 where the del order_list[choice] is. I've tried indenting and out denting. Looked at multiple sites and cannot find the reason to why this isn't running. It was given to us by the instructor to use and for some reason when he ran it, it seemed to work. I run it and error. Please help.
cannot understand why program will not run
Users browsing this thread: 2 Guest(s)