dimanche 6 décembre 2015

python Code not working with negative input

Okay so I been learning with some intro vids and I'm just learning but I couldn't find the answer to this problem when I searched. Here is the code:

import random
highest = 10
answer = random.randrange(highest)
guess = raw_input("Guess a number from 0 to %d: " %highest)
while (int(guess) != answer):
    if (int(guess) < answer):
        print "Answer is higher"
    elif (int(guess) > 10):
        print "You know that number is higher than 10 right?"
    elif (int(guess) < 0):
        print "You shouldn't be guessing numbers lower than zero dummy"
    else:
        print "Answer is lower"
    guess = raw_input("Guess a number from 0 to %d: "%highest)
raw_input("You're a winner Face!!!")

Now it works fine when I put in say 22 but when I input -3 it just says "integer is higher and not "You shouldn't be guessing numbers lower than zero dummy". I just put in the number like -4 but it gives me an error if I do it like this (-4). Am I missing something? Forgive me if this is really easy I'm kinda just starting to learn :)

Aucun commentaire:

Enregistrer un commentaire