Below is a piece of code from Python which has been bothering me for a while.
var=0
while (var <1 or var>100):
var=raw_input('Enter the block number ')
if (var >=1 and var<=100):
print '\nBlock Number : ',var
else:
print 'ERROR!!! Enter again.'
The problem is that the while loop iterates continuously without breaking. Can anyone help me how to break the loop.
Is there any way to implement a do..while in Python?
The problem is that
raw_inputreturns a string. You’re comparing a string with an integer which you can do in python 2.x (In python 3, this sort of comparison raises aTypeError), but the result is apparently alwaysFalse. To make this work you probably want something likevar=int(raw_input('Enter the block number'))From the documentation: