mardi 10 août 2021

Python if else statement based on sign

I tried to transform a list of numbers into the list of the signs of the numbers from this list, while i have so many option to do so, I found a weird response from python3:

a =[0.5]
for x in a:
    if x > 0:
        print('sup 0')
    if x < 0:
        print('inf 0')
    else:
        print('egal 0')

output: sup 0 egal 0

Can someone explain me why this output occur ?

Best regards

Aucun commentaire:

Enregistrer un commentaire