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
如何返回循环python中的某个点_Python_Loops - Fatal编程技术网

如何返回循环python中的某个点

如何返回循环python中的某个点,python,loops,Python,Loops,这是我的一段代码,基本上在“else”之后,我想返回一行代码,上面写着“correct1=input(“is this correct>\n”)”,但我不知道怎么做。任何帮助都将不胜感激。如果您将while循环移动到print(“您的名字是”,firstName.title()),您的程序可能会执行与当前相同的操作,同时也会在需要时返回while循环的开始处。这应该可以: while True: firstName = input("Please enter your First Nam

这是我的一段代码,基本上在“else”之后,我想返回一行代码,上面写着“correct1=input(“is this correct>\n”)”,但我不知道怎么做。任何帮助都将不胜感激。

如果您将while循环移动到print
(“您的名字是”,firstName.title())
,您的程序可能会执行与当前相同的操作,同时也会在需要时返回while循环的开始处。

这应该可以:

while True:
    firstName = input("Please enter your First Name\n")
    print ("Your First Name is", firstName.title())
    correct1 = input("Is this correct?\n")
        if correct1.lower() == "yes":
            break
        if correct1.lower() == "no":
            continue
        else:
            print ("Please say yes or no")

我创建了一个名为
correct\u name
的变量,并将其设置为
False
。因此,当
correct\u name
False
时,程序将继续询问用户的姓名,直到他们说是。一旦他们说是,节目就会结束。

是@GreenSaber答案的延伸。您需要添加一个嵌套循环,以便在他们不输入
yes
no
时继续询问
这是否正确?
,但除非他们输入
no
,否则不要再次询问名称

correct_name = False
while correct_name == False:
    firstName = input("Please enter your First Name\n")
    print ("Your First Name is", firstName.title())
    print ("Please say yes or no")
    correct1 = input("Is this correct?\n")
    if correct1.lower() == "yes":
        correct_name = True
    else:
        correct_name = False

我想返回代码行您的意思是我想返回代码行吗?这就是我的意思是,当我运行acutal代码时,它告诉我说是或否,而不是返回“请输入您的名字”,我想让它说“这是否正确?”
correct1
在内部循环中阅读:
correct1=”“
,然后:
而correct1.lower()不在[“是”、“否”]:
…-欢迎光临,您想租辆车吗?请说“是”或“不是”-是-那很好!首先我们需要了解一些细节-请输入您的名字-塔兰-您的名字是塔兰-这是正确的吗-abc-请说是或否-请输入您的名字这是我运行代码后遇到的问题。与上面的代码相同^i希望它说“请说是或否”,然后说“这是正确的吗?”好的,等一下!我会改变我的答案的,伙计们,Mistermystry代码已经生效了,谢谢你的帮助:)@Tazzy3我想这就是你想要的
correct_name = False
while correct_name == False:
    firstName = input("Please enter your First Name\n")
    print ("Your First Name is", firstName.title())
    while True:
        correct1 = input("Is this correct?\n")
        if correct1.lower() == "yes":
            correct_name = True
            break
        if correct1.lower() == "no":
            correct_name = False
            break
        else:
            print ("Please say yes or no")