Report this

What is the reason for this report?

python rock paper scissors game

Posted on December 27, 2020

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.