[Python] Creating divide function in Python [closed]

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a function to divide two numbers. But when I input 0 as the second number, it gives an error.

    def divide(a, b):
    return a / b

    print(divide(10, 0))


    I tried using if b != 0: before dividing, but still learning how to use try-except.

    How can I handle this error properly?

    Continue reading...

Compartilhe esta Página