Skip to content
Advertisement

im trying to make a score system for my rock paper scissors python game. I want it to be best 2 out of 3

This is all I have of the code, so far you can play rock, paper, scissors and see who wins or loses. I need help making a scoring system. Best two out of three is the final winner. Also I need help with how I would rerun the game until one of the players gets 2 points. Right now, the user has to manually type yes to replay the game which I would be fine with I just cant figure out how I would keep score.

#ROCK PAPER SCISSOR
import random

while True:
    # variables
    rpc = ["rock","paper","scissor"]
    player = None
    player_score = 0
    comp_score = 0

    # player and comp choice
    while player not in (rpc):
        player = input("rock, paper, or scissor: ").lower()

    comp = random.choice(rpc)

    print("Rock, Paper, or Scissor?: ")

    # player wins or loses
    if player == comp:
        print("player: ", player)
        print("computer: ", comp)
        print("TIE!")

    elif player == "rock":
        if comp == "paper":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score = 1
        if comp == "scissor":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score = 1

    elif player == "scissor":
        if comp == "rock":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score = 1
        if comp == "paper":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score = 1

    elif player == "paper":
        if comp == "scissor":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score = 1
        if comp == "rock":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score = 1

    #Score
    print("your score:", player_score)
    print("computers score: ", comp_score)

    player_choice = input("keep playing?: yes/no").lower()

    if player_choice == "no":
     break

print("Goodbye")

Advertisement

Answer

#ROCK PAPER SCISSOR
import random

player_score = 0
comp_score = 0

while True:
    # variables
    rpc = ["rock","paper","scissor"]
    player = None

    # player and comp choice
    while player not in (rpc):
        player = input("rock, paper, or scissor: ").lower()

    comp = random.choice(rpc)

    # player wins or loses
    if player == comp:
        print("player: ", player)
        print("computer: ", comp)
        print("TIE!")

    elif player == "rock":
        if comp == "paper":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score += 1
        if comp == "scissor":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score += 1

    elif player == "scissor":
        if comp == "rock":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score += 1
        if comp == "paper":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score += 1

    elif player == "paper":
        if comp == "scissor":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU LOSE!")
            comp_score += 1
        if comp == "rock":
            print("player: ", player)
            print("computer: ", comp)
            print("YOU WIN!")
            player_score += 1

    #Score
    print("your score:", player_score)
    print("computers score: ", comp_score)

    # player_choice = input("keep playing?: yes/no").lower()

    if player_score == 2:
        print("player wins")
        break
    
    elif comp_score == 2:
        print("computer wins")
        break

print("Goodbye")
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement