dimanche 19 juin 2016

I can't see what is wrong with my IF statment

I just stared with python, and wanted to do a small beginner program that generates a random number, and the user need to guess it after the input.

I want something more after this, but i can't make it working, perhaps because of (probably) syntaxs errors.

from random import randint

magic_number = randint(0, 20)
user_input = 21
true = 1


while user_input is not magic_number:
    user_input = input('Please state your number')
    print(magic_number)
    print(user_input)
    if magic_number == user_input:
        print(user_input, "is the right number")
    print(user_input)

on my eyes i dont see any OBVIOUS mistake.. but it is never going inside that if, making me wonder why.

my console shows me the following.

Please state your number10
17
10
10
Please state your number17
17
17
17
Please state your number

even after "guessing" the right number, is just doesnt go inside that if. i used to have break after that print inside that IF, but i deleted thinking it my be the problem ( it wouldn't make any sence tho)

thanks in advance

Aucun commentaire:

Enregistrer un commentaire