Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LauraGaleev opened this issue Mar 6, 2023 · 0 comments
Open

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

LauraGaleev opened this issue Mar 6, 2023 · 0 comments

Comments

@LauraGaleev
Copy link

LauraGaleev commented Mar 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant