0

This is a Rock Paper Scissor Game. While running the program, I want it to end only while right input is entered, if not, it will loop until the right input is given. When running the program and entering a wrong input, the loop begins, but it is not ending by entering a right input again.

This is my code:

from getpass import getpass as input
print('''
EPIC ROCK  PAPER  SCISSORS ✂️ BATTLE ⚔️!
++++++++++++++++++++++++++++++++++++++++++++++
''')
player1 = input("""
Player 1 Please Enter Your Move
R = 
P = 
S = ✂️
""")
player2 = input("""
Player 2 Please Enter Your Move
R = 
P = 
S = ✂️
""")
if player1 == "R" and player2 == "S":
  print("Player 1 Won")
elif player1 == "R" and player2 == "P":
  print("Player 2 Won")
elif player1 == "R" and player2 == "R":
 print("It is a Tie ")
elif player1 == "P" and player2 == "R":
  print("Player 1 Won")
elif player1 == "P" and player2 == "S":
  print("Player 2 Won")
elif player1 == "P" and player2 == "P":
  print("It is a Tie ")
elif player1 == "S" and player2 == "S":
  print("It is a Tie ")
elif player1 == "S" and player2 == "P":
  print("Player 1 Won")
elif player1 == "S" and player2 == "R":
  print("Player 2 Won")
else:
  print("Wrong Move, Please Try Again")
  while player1 == "P" or player1 != "S" or player1 != "R" or player2 != "P" or player2 != "S" or player2 != "R":
    print('''
EPIC ROCK  PAPER  SCISSIORS ✂️ BATTEL ⚔️!
++++++++++++++++++++++++++++++++++++++++++++++
''')
    player1 = input("""
    Player 1 Please Enter Your Move
    R = 
    P = 
    S = ✂️
    """)
    player2 = input("""
    Player 2 Please Enter Your Move
    R = 
    P = 
    S = ✂️
    """)
    if player1 == "R" and player2 == "S":
      print("Player 1 Won")
    elif player1 == "R" and player2 == "P":
      print("Player 2 Won")
    elif player1 == "R" and player2 == "R":
     print("It is a Tie ")
    elif player1 == "P" and player2 == "R":
      print("Player 1 Won")
    elif player1 == "P" and player2 == "S":
      print("Player 2 Won")
    elif player1 == "P" and player2 == "P":
      print("It is a Tie ")
    elif player1 == "S" and player2 == "S":
      print("It is a Tie ")
    elif player1 == "S" and player2 == "P":
      print("Player 1 Won")
    elif player1 == "S" and player2 == "R":
      print("Player 2 Won")
print('''
Thanks for Playing
EPIC ROCK  PAPER  SCISSIORS ✂️ BATTLE ⚔️!
++++++++++++++++++++++++++++++++++++++++++++++
''')
U13-Forward
  • 69,221
  • 14
  • 89
  • 114

2 Answers2

0

Welcome to Stack Overflow. This should do the trick.

First, it checks if both inputs are right using in [...]. I have made both uppercase, so you don't get a wrong input if the user writes that letter in lowercase.

Then, it just goes through the normal Rock Paper Scissors logic. One thing I have improved there as well, is that instead of checking for each tie case individually, I do it just once in the beginning by checking both inputs against each other.

I hope this helps you further. If you have any other questions, feel free to ask them :)

from getpass import getpass as input

print('''
EPIC ROCK  PAPER  SCISSORS ✂️ BATTLE ⚔️!
++++++++++++++++++++++++++++++++++++++++++++++
''')
player1 = input('''
Player 1 Please Enter Your Move
R = 
P = 
S = ✂️
''')
player2 = input('''
Player 2 Please Enter Your Move
R = 
P = 
S = ✂️
''')

while player1.upper() not in ['R', 'P', 'S'] or player2.upper() not in ['R', 'P', 'S']:
    print('Invalid Input! Please Try Again!')
    player1 = input('''
    Player 1 Please Enter Your Move
    R = 
    P = 
    S = ✂️
    ''')
    player2 = input('''
    Player 2 Please Enter Your Move
    R = 
    P = 
    S = ✂️
    ''')

    if player1 == player2:
        print('It is a Tie ')
    elif player1 == 'R' and player2 == 'S':
        print('Player 1 Won')
    elif player1 == 'R' and player2 == 'P':
        print('Player 2 Won')
    elif player1 == 'P' and player2 == 'R':
        print('Player 1 Won')
    elif player1 == 'P' and player2 == 'S':
        print('Player 2 Won')
    elif player1 == 'S' and player2 == 'P':
        print('Player 1 Won')
    elif player1 == 'S' and player2 == 'R':
        print('Player 2 Won')


print('''
Thanks for Playing
EPIC ROCK  PAPER  SCISSORS ✂️ BATTLE ⚔️!
++++++++++++++++++++++++++++++++++++++++++++++
''')
S-Flavius
  • 292
  • 2
  • 14
  • Hello @PuneetSharma, although this question has been closed, I want to let you know that if my answer was helpful to you, you can mark it as the solution to your question by clicking the checkmark next to it. This will help others find the answer more easily if they come across this question in the future. Thanks for using this platform and I hope to see you again. – S-Flavius Dec 21 '22 at 07:25
0
while(player1!="P" or player1!="R" or player1!="S"):
  player1 = input("""
  Player 1 Please Enter Your Move
  R = 
  P = 
  S = ✂️
  """)

Try taking the input from each user from inside a while loop. Loop until they enter a valid input and you move to the next statements once they enter a valid loop. Repeat the above for player2