Python 为什么';";而";语句是否识别变量中的更改?
我使用while语句保持输入,直到满足一个条件,但它没有看到变量值的变化,并保持循环。它还开始跳过行,直到自己终止。这看起来像是递归,但我对此不太了解。这是我的代码…#加载 这是Python 为什么';";而";语句是否识别变量中的更改?,python,Python,我使用while语句保持输入,直到满足一个条件,但它没有看到变量值的变化,并保持循环。它还开始跳过行,直到自己终止。这看起来像是递归,但我对此不太了解。这是我的代码…#加载 这是 First lot #: 1 Last lot #: 3 ?: #entered "return" #printed empty space Error ?: 2 2 ?: 3
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
这似乎是非常基本的循环。如果有人对此有所了解,这将是一个非常值得重视的小缩进问题
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
你有两个循环。看起来第二个循环的作用很僵硬,实际上是代码经过了一段时间(因为它确实看到了变量中的变化),然后返回到外部。之后,您的输入将阻止while再次执行。不知道为什么这个问题被认为是离题的!
?:
Error
?: 1
1
?: 2
2
?: 3
3