[Python] How can I make a function that takes either one or two arguments?

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    I've been tasked with making a function that will work like:

    >>> CurryPuff(3)
    3.60
    >>> CurryPuff(3,'Fish')
    4.2


    I tried this code:

    def CurryPuff(x,typePuff):
    if (typePuff==''):
    return x*1.2
    if (typePuff=='Fish'):
    return x*1.4


    But I get an error that says:

    TypeError: CurryPuff() takes exactly 2 arguments (1 given)


    What does this error mean?

    How can I make it so that both calls will work?

    Continue reading...

Compartilhe esta Página