Report this

What is the reason for this report?

python rock paper scissors game

Posted on December 28, 2020

so i was just making a python rock paper scissors game and it has a score limit of 5. so if either the user or the computer reaches the score of 5, the game will print the person won or the computer won respectively. but it prints it if the computer wins only and also when the user wins the game doesn’t end and it doesn’t print that the user won. pls help me this is my code:

import random

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


while user_score != score_limit or pc_score != score_limit:

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

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

    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 )

        pc_guess = random.choice ( my_list )

        if user_score == score_limit:
            print("yay congrats u won")

        elif pc_score == score_limit:
            print("oopsies, the computer won, better luck next time")

            break


This textbox defaults to using Markdown to format your 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.

Hi there,

This looks quite good! You just need to move the last if else statement out of the previous if statement like this:

import random

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


while user_score != score_limit or pc_score != score_limit:

    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)

    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 )

        pc_guess = random.choice ( my_list )

    if user_score == score_limit:
        print("yay the u won")

        break

    elif pc_score == score_limit:
        print("oopsies, the computer won, better luck next time")

        break

Hope that this helps! Regards, Bobby

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.