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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -