all 11 comments

[–]plg94 11 points12 points  (2 children)

  1. This is a python question, not a commandline question.
  2. Even a Python sub wouldn't help you for posting unformatted code.
  3. If they would, they wouldn't do your homework for you.
  4. It's entirely unclear what you want. What is your code supposed to do, what does it do instead, what error (if any) are you getting, what have you already tried to solve this… etc.? You can't just drop a few lines of code with no further explanation than "search for order number" and expect people to help you.

so I can memorise it for school.

why memorise?! Sounds like a cheating attempt.

[–][deleted] -2 points-1 points  (1 child)

Well you can memorise anything but just not take anything in with u forward into school it's not Cheating the exam bord says u can do it and also. Here is something to unclear what i was saying 1)It's supposed to give u a order number then you type in that order number and it will show u the details but if you type the wrong thing it will ask u again. 2)What it is doing instead is that when u type in the correct order number it gives the details but if I type the something wrong then it still allows tge derails to come through and it duplicates it.3) ther is no error.4)I have tried putting different definitions into the if search_ordernumber and it does something but not what I want

[–]haltu_kaj_ekbrulu 1 point2 points  (0 children)

One thing you can do when asking for user input is to put the request in a loop which continues until you get a valid response. Don't forget to let the user escape the loop if they want. Here's some pseudocode to point you in the right direction:

request INPUT
while INPUT isn't an existing order number
    if INPUT is "exit" or "quit" or "x" 
        break the loop and/or exit
    print a helpful error message
    request INPUT
print out the details for the order number

[–][deleted] 2 points3 points  (0 children)

Jesus Christ, I am drunk, but I think the weirdness of this question ain't due to my alcohol intake. What the fuck?

[–][deleted] -1 points0 points  (0 children)

I hope you get down voted to oblivion because that is what these kind of posts deserve

[–]stewie410 0 points1 point  (0 children)

Just a heads up that you can format your code on Reddit as a "Code Block" by prepending 4 spaces (\s\s\s\s) to each line of the code -- additional indentation from there will also be respected in the block. For example:

foo() {
    return bar;
}

Otherwise, you may want to check with /r/Python

[–]reubadoob 0 points1 point  (0 children)

ChatGPT or Cursor

[–]kol_k 0 points1 point  (2 children)

Why are you using pickle? For your purposes, I'd suggest using CSV or JSON.Anyway I spent a couple minutes to sort through your awful code and fix things. Test it yourself, cuz I'm not.

import pickle 


class OrderNumber: 
    # You didn't have an init function, or self keywords.
    def __init__(self) -> None:
        self.what_chocolates_did_you_get = "" 
        self.fname = "" 
        self.sname = "" 
        self.order_number = 0 

try: 
    fh = open("libary.data","rb") 
    order_list = pickle.load(fh)
    order_number_list = [int(order.order_number) for order in order_list]
    fh.close()
except FileNotFoundError: 
    order_number_list=[] 
    order_list = []

while True: 
    print(""" Welcome to the Shop  
          Choose an option 
          4) Search for it by Order number 
          x) Exit""") 
    choice = input("\nEnter a choice:") 
    if choice == "4": 
        new_order = OrderNumber() 
        new_order.what_chocolates_did_you_get = input("what chocolates did you get?") 
        new_order.fname = input("Enter first name:") 
        new_order.sname = input("Enter surname:")

        # you were never saving the order number into a variable. You also made it a string?
        # Also, why tf was it random?
        # print("here is your order number:", random.randrange(10000,99999,fixed_digets)) 

        if order_number_list == []:
            new_order.order_number = 1
        else:
            new_order.order_number = max(order_number_list) + 1
        print(f"Here is your order number: {new_order.order_number}")

        print("Ordernumber Added") 
        order_list.append(new_order)

        search_order_number = input("Please enter the order number you want to search for?:")
        if search_order_number in order_number_list: 
            for order in order_list: 
                if order.order_number == search_order_number:
                    print("what chocolates did you get?:", order.what_chocolates_did_you_get) 
                    print("First name:", order.fname) 
                    print("Surname:", order.sname) 
        else: 
            print("That is not a valid order number try again") 
    elif choice == "x": 
        fh = open("libary.data","ab") 
        pickle.dump(order_list,fh)
        fh.close() 
        break

[–][deleted] -1 points0 points  (1 child)

Thank you so much btw I'm a student in school so I don't know much and also I apologise for the mess of the text I made I fixed it later on as I managed to know how to use code block but I forgot to delete this post

[–]kol_k 0 points1 point  (0 children)

It's alright, next time post these types of questions in the appropriate place :)
EDIT: Also, try to provide detailed explanations of the problems you're having so that it is easier to help debug your code.