我正在使用while语句继续输入,直到满足条件但它没有看到变量值的变化并保持循环。它也开始跳过直到它自行终止。这看起来像递归,但我不太了解。这是我的代码...... #load
first = input("First lot #: ")
last = input("Last lot #: ")
for a in range(first,last +1):
draw=raw_input("?: ")
while draw==(""): #This is for erroneus input
print draw #" while" wasn't seeing the change of value in draw so I added
# print draw
print "Error" #" print draw" is skipped after the 1st time thruogh the loop
draw=raw_input("?: ")
print draw # this line is skipped after 2nd time thruogh loop
##
## while draw>35: #The same
## print"Error"
## draw=raw_input("?: ")
##
## num=(str(a),draw)
## num=str(num) # python thinks num is a tuple..another
## print num
##
## f = open("pb_loader","a")
## f.write(num)
## f.close()
##
##
##c=open("pb_loader","r")
##d=c.read()
##print d
##c.close()
##
这会得到.........
First lot #: 1
Last lot #: 3
?: #entered "return"
#printed empty space
Error
?: 2
2
?: 3 #skipped "print draw" at top of loop
?: 3 #skipped "print draw" at bottom of loop
>>> #terminated itself
这似乎是非常基本的循环。如果有人有一些见解,那将是非常令人遗憾的
答案 0 :(得分:2)
小缩进问题
first = input("First lot #: ")
last = input("Last lot #: ")
for a in range(first,last +1):
draw=raw_input("?: ")
while draw==(""): #This is for erroneus input
print "Error" #" print draw" is skipped after the 1st time thruogh the loop
draw=raw_input("?: ")
print draw # this line is skipped after 2nd time thruogh loop
结果是
?:
Error
?: 1
1
?: 2
2
?: 3
3