a simple python code that astonishingly ignores if condition & statement -


this question has answer here:

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -