Skip to content

Instantly share code, notes, and snippets.

@srahuliitb
Last active February 9, 2023 14:06
Show Gist options
  • Save srahuliitb/665b656bef30caf07007d06bce791afd to your computer and use it in GitHub Desktop.
Save srahuliitb/665b656bef30caf07007d06bce791afd to your computer and use it in GitHub Desktop.
Make a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game)
p1_call = raw_input("Player 1, Enter rock/paper/scissors: ")
p2_call = raw_input("Player 2, Enter rock/paper/scissors: ")
def rock_paper_scissors(player_1, player_2):
a_list = ["rock", "paper", "scissors"]
while player_1 not in a_list or player_2 not in a_list:
print "Invalid input. Please give a valid input."
player_1 = raw_input("Player 1, Enter rock/paper/scissors: ")
player_2 = raw_input("Player 2, Enter rock/paper/scissors: ")
while player_1 == player_2:
print "Nobody wins. Try again"
player_1 = raw_input("Player 1, Enter rock/paper/scissors: ")
player_2 = raw_input("Player 2, Enter rock/paper/scissors: ")
if player_1 == "rock" and player_2 == "paper":
print "Player 2 wins!"
elif player_1 == "paper" and player_2 == "rock":
print "Player 1 wins!"
elif player_1 == "rock" and player_2 == "scissors":
print "Player 1 wins!"
elif player_1 == "scissors" and player_2 == "rock":
print "Player 2 wins"
elif player_1 == "paper" and player_2 == "scissors":
print "Player 2 wins!"
elif player_1 == "scissors" and player_2 == "paper":
print "Player 1 wins!"
rock_paper_scissors(p1_call, p2_call)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment