a simple python code that astonishingly ignores if condition & statement -
this question has answer here:
- how can read inputs integers? 14 answers
i have simple code here. problem bothering me. in line no 7, there if-condition; astonishingly if condition never addressed! ran program , checked multiple times using python version 2.7. behaves if if-condition , statements (along break) inside comment , 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 never checked? print ('you win!') break guesses_left -= 1 else: print ('you lose.')
have considered random_number
integer, while raw_input()
returns string? means guess
string. try converting variables same type!
since types differ, values not equal, though may appear when printed. in other words 3 != "3".
Comments
Post a Comment