-3

I am trying to create a loop until the correct input is inputted but if a wrong answer is inputted, the code loops around the "print ("Invalid input, check spelling error")" forever. What am I supposed to do so that the entire code repeats again re-asking for an input?

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")

This is my first question ever so my apologies if its pretty pointless or already asked. If it is asked I would also appreciate a link or the title to that question.

Meepwned
  • 7
  • 2

1 Answers1

0
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")

This code will keep asking for an input until ChosenProcessor is equal to one of your inputs. If ChosenProcessoris equal to one of your inputs the loop will stop. (break exits a while/for loop)

elmuscovado
  • 114
  • 3
  • 6
  • 13
  • Ah I just realized the silly mistake I made now thanks to you, man, it sure is annoying to not see the mistakes you make even though its right in front of you and so obvious. – Meepwned Jan 09 '18 at 19:55