[Python] How to make user choose his own function

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently studying programming and I have the following problem.

    A user should enter the operation that he wants to do from the command line and according to the operation, he should enter the information about the item.

    I have tried things like the following:

    def stock(f):
    d={}
    f()
    return d


    def add(item,amount):
    d[item]=amount
    return d


    Or

    def stock(item,amount,f):
    d={}
    if f():
    d[item]=amount
    return d


    def add():
    return True


    and, second one doesn't work for me because, when i want to use this code remove(a,b) i don't need three argument. What i'm trying to say is number of argument changes according to my operations. How do i handle this.

    Continue reading...

Compartilhe esta Página