Open LauraGaleev opened 1 year ago
Solution on Replit had errors. I made some changes:
import random
def rpsPlay(player1, player2): """ input: player1 and player2 should each be 'rock', 'paper', or 'scissors' output: the outcome of the game """
if player1 == player2: print("It's a tie!")
elif player1 == "scissors": if player2 == "rock": print ("Player 2 won!") else: print("Player 1 won!")
elif player1 == "rock": if player2 == "scissors": print ("Player 1 won!") else: print("Player 2 won!")
else: if player2 == "scissors": print ("Player 2 won!") else: print("Player 1 won!")
rps = ['rock', 'paper', 'scissors']
def choose_rps(): "output: randomly returns rock, paper, or scissors" r = random.randint(0,2) print(r) return rps[r]
def play_again(): "output: 1 or 0 for play again or not" r = random.randint(0,1) return r
play = True
print("Welcome to Rock, Paper, Scissors!") print("------") while play == True: player1 = choose_rps() player2 = choose_rps() print(f"Player 1 chose {player1}") print(f"Player 2 chose {player2}\n") rpsPlay(player1, player2) play = play_again() print("------")
print("Thank you for playing!")
Solution on Replit had errors. I made some changes:
import random
rps function
def rpsPlay(player1, player2): """ input: player1 and player2 should each be 'rock', 'paper', or 'scissors' output: the outcome of the game """
--game logic--
tie
if player1 == player2: print("It's a tie!")
player1 = scissors
elif player1 == "scissors": if player2 == "rock": print ("Player 2 won!") else: print("Player 1 won!")
player1 = rock
elif player1 == "rock": if player2 == "scissors": print ("Player 1 won!") else: print("Player 2 won!")
player1 = paper
else: if player2 == "scissors": print ("Player 2 won!") else: print("Player 1 won!")
rps = ['rock', 'paper', 'scissors']
def choose_rps(): "output: randomly returns rock, paper, or scissors" r = random.randint(0,2) print(r) return rps[r]
def play_again(): "output: 1 or 0 for play again or not" r = random.randint(0,1) return r
play = True
print("Welcome to Rock, Paper, Scissors!") print("------") while play == True: player1 = choose_rps() player2 = choose_rps() print(f"Player 1 chose {player1}") print(f"Player 2 chose {player2}\n") rpsPlay(player1, player2) play = play_again() print("------")
print("Thank you for playing!")