Python Forum
Function not working as intended I think?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function not working as intended I think?
#1
I'm having some trouble with the last part I need to finish for my code, this darn function lol. disp_order is suppose to show like what you've ordered so far but when I call it, it just says you've ordered 0 and not showing the correct order. It also doesn't show correctly when I input "m" as my choice which is suppose to display your order. I'm happy there aren't any errors though so that's nice.

 
import locale
locale.setlocale( locale.LC_ALL, '')

order_total = 0.0      # Dollar Total 
price = 3.5
item_qty = 0
#Cookie Price
fmt_price = locale.currency(price, grouping=True)

#Cookie list
#***********
cookie_list = []
cookie_list = "Savanah Thinmints Tagalongs".split()

order_list = []

#Display cookie choices
#**********************
def disp_items():

    print("Please choose a flavor. Enter the item number to choose")

    for c in range(len(cookie_list)):
        print("{}.\t{}".format(c+1, cookie_list[c]))

    print()
    
#Options Menu
#************
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 the order so far")
        print("q = quit")
        choice = input("\nPlease make a selection:")

        if choice in choice_list:
            return choice
        else:
            print("I do not understand that selection, please try again")

def calc_tot(item_qty):

    return item_qty * 3.5


    
def disp_order():
    
    fmt_total = locale.currency(order_total, grouping=True)
    print("\You ordered {} boxes(s) for a total price of {}".format(order_total, fmt_total))
    
#Add Process
#***********

def add_process():

    valid_data = False

    while not valid_data:

        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 entry, please try again")

        except Exception as detail:
            print("error: ", detail)

    valid_data = False #Reset

  ##### Validate Quanity######
    while not valid_data:

        try:

            qty = int(input("enter quanity you'd like:"))

            if 1 <= qty <= 10:
                valid_data = True
            else:
                print("\nThat was not a valid entry, please try again")

        except Exeception as detail:
            print("error: I do not reconigze that entry", detail)
            print("Please try again")
                     
    item_total = calc_tot(qty)
    fmt_total = locale.currency(item_total, grouping=True)
    

    #user choice
    print("\nYou chose: {} 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 oder".format(cookie_list[inx]))

        elif incl.lower() == "n":
            print("{} was not added to your order".format(cookie_list[inx]))

        else:
            print("I do not recognize that entry, please try again")


#Delete process

def del_item():
    if len(order_list) == 0:
        print("\n** you have no items in your order to delete")
    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("item {}. {} with {} boxes will be deleted".format(choice + 1,
                                                                                order_list[choice][0],
                                                                                order_list[choice][1]))
                    del order_list[choice]
                    del order_list[choice]
                    valid_data = True

            except Exception as detail:
                   print("error: Sorry I don't recognize that entry ", detail)
                   print("please try again")



                              
    
 ########MAIN PROGRAM#########
print("Hello thank you for buying girl scout cookies")
person = input("please enter your name:")

while True:

    choice = disp_menu()

    if choice == "a":
        add_process()
    elif choice == "d":
        del_item()
    elif choice == "m":
        disp_order()
    elif choice == "q":
        break
    disp_order()

    

disp_order()
print("Thank you for your order")
Reply
#2
Guessing the only response is spam...lol.
Reply
#3
I think the other post was not related (i.e. hi-jack this thread) and I split in separate thread
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why this reverse lookup function not working Emekadavid 4 2,314 May-31-2020, 05:54 AM
Last Post: Emekadavid
  GUI and function not working together albry 2 2,566 Jan-15-2019, 07:32 AM
Last Post: albry
  Simple IF statement not working as intended gortexxx 2 2,787 May-17-2018, 07:54 PM
Last Post: gortexxx
  For and If Loop not working as intended Jaykin 1 2,599 Apr-29-2018, 01:14 PM
Last Post: j.crater
  [split] Function not working as intended mihshyahoocom 1 2,101 Mar-11-2018, 09:04 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020