vendredi 23 février 2018

The If statement evaluates False condition even when the condition is True [duplicate]

This question already has an answer here:

On function when the value of random integer generated by computer and the guess number given by the user matches the IF statement doesn't evaluates to True. What is the possible cause of malfunction in this program.

##In this program, the user must try to guess a random number generated by the computer
from random import randint
def guess_game():
    """ A function to check whether the number guessed by the user matches the number generated by computer"""

    while True:
        random_num = randint(0,10)
        print random_num
        guess = raw_input("Enter a number: ")
        print guess
        if random_num == guess:
            print "your guess is correct"
            break
        else:
            print "Try Again"

guess_game()




Aucun commentaire:

Enregistrer un commentaire