Skip to content

Lesson 6: Project, RPS - Version 4. Error and Fix. #299

@LauraGaleev

Description

@LauraGaleev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions