I am trying to restart my program through While loop. After writing the whole program, I tell it to "Continue" and start the while loop again but it keeps giving me a syntax error. Can someone please explain me what am i doing wrong here? Please ignore the quality of code and focus on pointing out my error. Thanks!

while True:
input1 = int(input("Player one please enter your desired choice through    a number\n 1 for Rock\n 2 for Scissors\n 3 for Paper\n Enter here: "))
input2 = int(input("Player two please enter your desired choice through a number\n 1 for Rock\n 2 for Scissors\n 3 for Paper\n Enter here: "))


if input1 == input2:
    print("It's a tie")
elif input1 == 1 and input2 == 2 or input1 == 1 and input2 == 3:
    print("Player one WINS!")
elif input1 == 2 and input2 == 1:
    print("Player two WINS!")
elif input1 == 3 and input2 == 1:
    print("Player one WINS!")
elif input1 == 2 and input2 == 3:
    print("Player one WINS")
elif input1 == 3 and input2 == 2:
    print("Player two WINS!")
else:
    pass
x = int(input("Do you want to play another game?: Y/N: "))

if x == 'y':
continue
else:
break

Expected Result: Program runs again

Actual Result: SyntaxError: 'continue' not properly in loop

1 Answers

0
Community On

Your x was a int, you have to make it a String to compare strings. (use str())

Int:

x = int(input("Do you want to play another game?: Y/N: "))

String:

x = str(input("Do you want to play another game?: Y/N: "))

working version:

  try:
      while True:
         input1 = int(input("Player one please enter your desired choice through    a number\n 1 for Rock\n 2 for Scissors\n 3 for Paper\n Enter here: "))
         input2 = int(input("Player two please enter your desired choice through a number\n 1 for Rock\n 2 for Scissors\n 3 for Paper\n Enter here: "))

         if input1 == input2:
            print("It's a tie")
         elif input1 == 1 and input2 == 2 or input1 == 1 and input2 == 3:
            print("Player one WINS!")
         elif input1 == 2 and input2 == 1:
            print("Player two WINS!")
         elif input1 == 3 and input2 == 1:
            print("Player one WINS!")
         elif input1 == 2 and input2 == 3:
            print("Player one WINS")
         elif input1 == 3 and input2 == 2:
            print("Player two WINS!")
         else:
            pass

         # x = int(input("Do you want to play another game?: Y/N: "))
         x = str(input("Do you want to play another game?: Y/N: "))
         if x == 'y':
            continue
         else:
            break

   except ValueError:
      raise ValueError('no negative numbers')
   except TypeError:
      raise TypeError('wrong type')