Question

python rock paper scissors game

  • Posted December 27, 2020
  • Python

So I was just making a rock paper scissors game. I’m a beginner coder. I am coding so that there is a limit of scoring and that’s 5. so if either the user or the pc reaches that score the game should end. and also according to the user guess and the pc guess the score increases respectively. So I set up a while loop so that as long as the user score and the pc score is not equal to 5, the game should continue. but if both the user guess and pc guess are not the same, no one scores and it prints tie!!. but after I set up a while loop, it doesn’t print tie whenever both guesses are the same. and also it should also print user scored when the user scores. But it doesn’t do it now. Can someone help me? this is my code:

import random

user_score = int(0)
pc_score = int(0)
score_limit = 5


user_guess: str = input(str("pls enter your guess, rock/paper/scissors:"))


my_list = "rock", "paper", "scissors"
pc_guess = random.choice(my_list)
print("the computer chose", pc_guess)

while user_score and pc_score != score_limit:

    user_guess: str = input(str( "pls enter your guess, rock/paper/scissors:"))

    if pc_guess == "rock" and user_guess == "rock":
        print("Tie!!")

    if pc_guess == "paper" and user_guess == "paper":
        print("Tie!!")

    if pc_guess == "scissors" and user_guess == "scissors":
        print("Tie!!")

    if pc_guess == "paper" and user_guess == "rock":
        print("the computer scores")
        pc_score = pc_score + 1
        print( "the pc score is:", pc_score)

    if pc_guess == "rock" and user_guess == "paper":
        print("yay u scored")
        user_score = user_score + 1
        print( "the user score is:", user_score)

    if pc_guess == "rock" and user_guess == "scissors":
        print("the computer scored")
        pc_score = int(pc_score) + 1
        print("the pc score is:", pc_score)

    if pc_guess == "scissors" and user_guess == "rock":
        print("yay u scored")
        user_score = user_score + 1
        print("the user score is:", user_score)

    if pc_guess == "paper" and user_guess == "scissors":
        print("yay u scored")
        user_score = user_score + 1
        print("the user score is:", user_score)

    if pc_guess == "scissors" and user_guess == "paper":
        print("the computer scored")
        pc_score = int( pc_score) + 1
        print( "the pc score is:", pc_score)

        break
Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi there @anandu4115,

You need to change the condition for the while loop to this:

while user_score != score_limit or pc_score != score_limit:

That way it will run until either the user or the computer reaches the score limit.

Also, you would need to add the pc_guess = random.choice(my_list) at the end of the while loop again so that each iteration of the loop the computer has a different choice.

Hope that this helps! Regards, Bobby