Day 017 - Project 17 : Rock Paper Scissors Multiple Rounds

If you have any questions, comments or issues with this project please post them here!

In the common errors section,it is mentioned
“The moment you add the () you notice the color change of exit from white to yellow.”
–Well, that happens only in dark mode, otherwise it is brown to blue

Also, in the example given, exit () leads to
repl process died unexpectedly:

Is that behaviour correct?

Yep, that’s normal. exit() and equivalent functions in other languages will result in the same message. It’s just telling you the code didn’t finish running, it was stopped. I’m pretty sure the same message will show if you press the stop button up the top (which shows once you press run).

2 Likes

Hey there – loving the course so far. Wanted to ask – I did the logic with the if statements a bit differently as I didn’t nest inside the options for player 1 or player 2. I simply worked out all the different possibilities and since there aren’t that many, it didn’t create that much extra work.

Is there a problem with the logic in mine? https://replit.com/@evanaetor/day17100-days-rock-paper-scissors-continue#main.py

Nope, looks fine to me :slight_smile:

New and improved :rock: :page_facing_up::scissors: game!

https://replit.com/@JackAdem/Day-017-Project-17-Rock-Paper-Scissors-Multiple-Rounds?v=1

Day 17 of #Replit100DaysOfCode #100DaysOfCode.

1 Like
print("ROCK, PAPER, SCISSORS")
print("======================")
print()

R = "rock"
P = "paper"
S = "scissors"
player1_score = 0
player2_score = 0
round = 0

while True:
    round += 1
    print("Round", round)
    print("Select your move")
    P1 = input("Player 1, select your option (R, P, S): ")
    P2 = input("Player 2, select your option (R, P, S): ")
    if P1 == P2:
        print("It's a draw")
        print("Try again")
    elif (
        (P1 == S and P2 == P) or
        (P1 == R and P2 == S) or
        (P1 == P and P2 == R)
    ):
        print("Player 1 wins this round đź‘Ź")
        player1_score += 1
    elif (
        (P2 == S and P1 == P) or
        (P2 == R and P1 == S) or
        (P2 == P and P1 == R)
    ):
        print("Player 2 wins this round đź‘Ź")
        player2_score += 1

    print("Player 1 Score:", player1_score)
    print("Player 2 Score:", player2_score)
    continue
    if player1_score >= 3:
        print("Player 1 is the champion!")
        break
    elif player2_score >= 3:
        print("Player 2 is the champion!")
        break

print("Thanks for playing")

Hey, @borobert2322 welcome to the forums!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

1 Like

There’s a typo in the answer for 06- day 17 challenge.md (“coridoor”):

print("You are in a coridoor, do you go left or right?")

The quiz has it correctly written, however:

print("You are in a corridor, do you go left or right?")

**Question: Am I doing this correctly? *

Tutorial number: i.e. Day 17

**Repl link: https://replit.com/@wittphoonsiri/day17100-days

So I’m a bit stuck right now. I can kinda understand the instructions but unsure if I am doing it correctly or not. I create two versions btw but I don’t know if both of them are wrong or not? Can anyone help please?:

First version:

print("E P I C    🪨  📄 ✂️    B A T T L E ")
print()
print("Select your move (R, P or S)")
print()

counter1 = 0
counter2 = 0
while True: 
  player1Move = input("Player 1 > ")
  print()
  player2Move = input("Player 2 > ")
  print()
  counter1 += 1
  counter2 += 1
  if player1Move == "R" and player2Move == "S":
    print("Player1's rock smashed Player2's scissor")
    print("Player1 wins round", counter1)
  elif player1Move == "P" and player2Move == "R":
    print("Player1's paper smothered Player2's rock")
    print("Player1 wins round", counter1)
  elif player1Move == "S" and player2Move == "P":
    print("Player1's scissor cutted Player2's paper")
    print("Player1 wins round", counter1)
    print("Player1 wins the game!")
    break 
  elif player1Move == "R" and player2Move == "P":
    print("Player2's paper smothered Player1's rock")
    print("Player2 wins round", counter2)
  elif player1Move == "P" and player2Move == "S":
    print("Player2's scissor cutted Player1's paper")
    print("Player2 wins round", counter2)
  elif player1Move == "S" and player2Move == "R":
    print("Player2's rock smashed Player1's scissor")
    print("Player2 wins round", counter2)
    print("Player2 wins the game!")
    exit()
  else: 
    continue

Second version:


TL4 edit

Both are wrong (if I understand the instructions correctly).

So, you need two variables to keep track of each player’s wins. You only increment one of the variables when one of the players wins a round.

Then, after the round ends, near the end of the while loop, you check both scores to see if either has won a total of 3 rounds (or custom amount). If so, that player wins the game and you break out of the loop. Do not break or exit() unless a player wins the game.

You should also have a single variable to keep track of how many rounds there have been.

Apologies, just noticed that the second version of my post is the same as the first one. Should have post this instead:

counter1 = 0
counter2 = 0
while True:
  player1Move = input("Player 1 > ")
  print()
  player2Move = input("Player 2 > ")
  print()

  if player1Move == "R":
    if player2Move == "R":
      print("You both picked Rock, draw!")
    elif player2Move == "S":
      print("Player1 smashed Player2's Scissors into dust with their Rock!")
      print("Player1 wins round", counter1)
    elif player2Move == "P":
      print("Player1's Rock is smothered by Player2's Paper!")
      print("Player2 wins round", counter2)
    else:
      print("Invalid Move Player 2!")
      continue
  elif player1Move == "P":
    if player2Move == "R":
      print("Player2's Rock is smothered by Player1's Paper!")
      print("Player1 wins round", counter1)
    elif player2Move == "S":
      print("Player1's Paper is cut into tiny pieces by Player2's Scissors!")
      print("Player2 wins round", counter2)
    elif player2Move == "P":
      print("Two bits of paper flap at each other. Dissapointing. Draw.")
    else:
      print("Invalid Move Player 2!")
      continue
  elif player1Move == "S":
    if player2Move == "R":
      print("Player 2's Rock makes metal-dust out of Player1's Scissors")
      print("Player2 wins round", counter2)
      print("congratulations, Player2 win 3 rounds!")
      break
    elif player2Move == "S":
      print("Ka-Shing! Scissors bounce off each other like a dodgy sword fight! Draw.")
    elif player2Move == "P":
      print("Player1's Scissors make confetti out of Player2's paper!")
      print("Player1 wins round", counter1)
      print("congratulations, Player1 win 3 rounds!")
      exit()
    else:
      print("Invalid Move Player 2!")
      continue
  else:
    print("Invalid Move Player 1!")
    continue

English is my second language so sorry if I’m a bit confused. What does increment mean in this case? Can you simplified for me what I need to fix?

Also should I have two variables or only one? The “counter” in the code is the variable to keep track of the rounds.

Increment means to add one.

You aren’t keeping track of the players’ scores. You can use a variable which you increment each time someone wins.

2 Likes

Add one as in “+= 1”?

But aren’t the “counter1 =0 and counter 2=0” that I keep as variables not keeping track of the score? Or am I doing something wrong?

Sorry for asking this. I’m pretty much a new beginner to python and programming in general.

In the second version, you never add 1 to the counters. In the first version, you add 1 to the counters every round.
But it should add 1 to counter1 when player1 wins, and add 1 to counter2 when player2 wins.
Then, when counter1 or counter2 get to 3, print the winner and use break statement.

2 Likes

What do you want the counter to do? Show what round we’re on, or, keep track of score?

Score, as in the amount of rounds each player has won.

I want the counter to keep track of the score. Should I use another variable?

Yeah. And each time a player wins, increment (+= 1) their score.

Also, you only need one counter variable.

counter = 0

player1Score = 0
player2Score = 0

while True:
  counter += 1
  ...

  if player1Move == "R":
    ...
    elif player2Move == "S":
      ...

      player1Score += 1
    elif player2Move == "P":
      ...

      player2Score += 1

  ...

And do the same for the other times a player wins.

2 Likes

How do I fix this? I don’t know where to place the break command

The break command has to be in the loop, so you just need to indent lines 9-47 to be inside the loop.

1 Like