jeudi 12 novembre 2020

How to reference input variable in subsequent "if" function? [closed]

I am just starting to pick up python and have come across an issue with referencing the input variable in subsequent "if" function (as seen below).

def sign(x):

    x=int(input())
            
    if x > 0:
        return 1
    
    elif x < 0:
        return -1
    
    else: 
        return 0

I have tried having the input function inside and outside of the sign() module but both returns the value of x instead of the 1-/1/0.

Please help. Thanks.

Aucun commentaire:

Enregistrer un commentaire