Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 我能';我好像不懂循环_Loops_Python 2.7 - Fatal编程技术网

Loops 我能';我好像不懂循环

Loops 我能';我好像不懂循环,loops,python-2.7,Loops,Python 2.7,是的,我是新来的,学习起来很困难。这让我很困惑。我已经尝试了几个小时来创建一个循环,如果变量的值不是它应该的值,它将继续请求原始输入,直到它是它应该的值,程序移动到下一个函数,以及显示类似“重试”的内容。这可能很简单,但我无法理解。我说的是第一个动作=原始输入(“>>”)之后的代码 你想要这样的东西: inp = '' desired = 'hello' while inp != desired: inp = raw_input('Enter a greeting: ') 这将继续请求

是的,我是新来的,学习起来很困难。这让我很困惑。我已经尝试了几个小时来创建一个循环,如果变量的值不是它应该的值,它将继续请求原始输入,直到它是它应该的值,程序移动到下一个函数,以及显示类似“重试”的内容。这可能很简单,但我无法理解。我说的是第一个动作=原始输入(“>>”)之后的代码


你想要这样的东西:

inp = ''
desired = 'hello'
while inp != desired:
    inp = raw_input('Enter a greeting: ')
这将继续请求输入,直到
inp
达到
所需的

>>> inp = ''
>>> desired = 'hello'
>>> while inp != desired:
...     inp = raw_input('Enter a greeting: ')
... 
Enter a greeting: bye
Enter a greeting: no
Enter a greeting: what's up
Enter a greeting: hello
>>> 
在代码中:

first_action = raw_input(">> ")

while first_action != "False::
    print "Try again"
    first_action = raw_input(">> ")
print "You lay on the grass for a hardly restful sleep."
day_1()
first_action = raw_input(">> ")

while first_action != "False::
    print "Try again"
    first_action = raw_input(">> ")
print "You lay on the grass for a hardly restful sleep."
day_1()