Question

python rock paper scissors game

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

Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
December 28, 2020
Accepted Answer

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more