mercredi 30 septembre 2015

a simple python code that astonishingly ignores if condition & statement [duplicate]

This question already has an answer here:

I have a really simple code here. But the problem is really bothering me. In line no 7, there is a if-condition; astonishingly this if condition is never addressed! I ran the program and checked multiple times using python version 2.7. It behaves as if the if-condition and its statements (along with break) is inside the comment and is simply ignored.

from random import randint
random_number = randint(1, 10)
guesses_left = 3
while (guesses_left>=1):
    print (random_number)
    guess = raw_input('Guess ?')      
    if guess == random_number: #this statement is never checked?
        print ('You win!')
        break
    guesses_left -= 1 
else:
    print ('You lose.')

Aucun commentaire:

Enregistrer un commentaire