if statement in python not executing -


from random import randint proceed = "y" while(proceed == 'y' or proceed == 'y'):     print("guess integer or 'exit'")     number = input()     x1 = randint(0, 9)     if number x1 :         print("you guessed right")     else:         print("number ", x1)     print("do want continue, y or n?")     proceed = input() 

in above code, if statement not executing. because of == operator not being used?

input returns string , therefore check:

if number x1 : 

will fail because string never same instance integer.

instead convert integer , check equality:

number = int(input()) x1 = randint(0, 9) if number == x1:     print("you guessed right") 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -