1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
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" ) |
cannot understand why program will not run
Users browsing this thread: 1 Guest(s)