jeudi 21 janvier 2021

How to use if else statements inside a try and except condition to find whether a not a number is positive, negative, or zero?

def algop(num):
    try:
        if num == 0:
            return "The number is neither positive nor negative"
    except:   
        sally = num + 1
        if num - sally == -1:
           return int(num), str("is positive")
        else:
           return int(num), str("Is negative")

print(algop(10))

The answer I get is "none". How can I get this to work?

Aucun commentaire:

Enregistrer un commentaire