jeudi 11 novembre 2021

Indicating the math before else [duplicate]

a = input()
b = input()


if b == 0:
    print("undefined")
else:
    w = (float(a) / float(b)); print(w)

So i was just trying some math and if statements but this catched my attention. It just executes the else before the if. Then when I am trying to divide the a by 0 but it just gives me error of dividing by zero when the else function shouldn't be even executed.

else:
    w = (float(a) / float(b)); print(w)

I know that dividing by zero is... stupid but i just wanted to test it out. Anyone know why it happens?

Aucun commentaire:

Enregistrer un commentaire