Python 循环直到输入正确

Python 循环直到输入正确,python,Python,我试图创建一个循环,直到输入正确的输入,但如果输入了错误的答案,代码将永远围绕“打印(“无效输入,检查拼写错误”)循环。我该怎么做才能使整个代码再次重复,重新请求输入 count = 0 while count == 0 : if ChosenProcessor == ("p3"): PCPrice = PCPrice + 100 count = count + 1 elif ChosenProcessor == ("p5"):

我试图创建一个循环,直到输入正确的输入,但如果输入了错误的答案,代码将永远围绕“打印(“无效输入,检查拼写错误”)循环。我该怎么做才能使整个代码再次重复,重新请求输入

count = 0

while count == 0  :

    if ChosenProcessor == ("p3"):
        PCPrice = PCPrice + 100 
        count = count + 1
    elif ChosenProcessor == ("p5"):     
        PCPrice = PCPrice + 120
        count = count + 1
    elif ChosenProcessor == ("p7"):
        PCPrice = PCPrice + 200
        count = count + 1
    else:
        print ("Invalid input, check spelling error")
这是我的第一个问题,所以如果它毫无意义或者已经被问到了,我道歉。如果有人问我这个问题,我也希望你能给我一个链接或标题

while True:

    ChosenProcessor = input('Enter the answer: ')

    if ChosenProcessor == ("p3"):
        PCPrice = PCPrice + 100
        break

    elif ChosenProcessor == ("p5"):     
        PCPrice = PCPrice + 120
        break

    elif ChosenProcessor == ("p7"):
        PCPrice = PCPrice + 200
        break

    else:
        print ("Invalid input, check spelling error")

此代码将一直请求输入,直到
ChosenProcessor
与您的输入之一相等。如果
ChosenProcessor
等于您的输入之一,循环将停止。(
break
退出while/for循环)

你应该从正确缩进代码开始。提示用户输入的代码在哪里?Meepwed这有点重要,因为你在哪里以及如何做是问题的核心。啊,我刚刚意识到我现在犯的愚蠢错误,多亏了你,伙计,虽然错误就在你面前,而且很明显,但是你没有看到你犯的错误,这确实令人恼火。