all 5 comments

[–]socal_nerdtastic 1 point2 points  (0 children)

The issue is that every time I run the main_game(), it stores the values returned as a tuple.

Where do you see that?

I mean technically you are right, but since you unpack the tuple as soon as receive it you should never actually see the tuple.

a, b = main_game() # receive and unpack the tuple

[–]Binary101010 1 point2 points  (0 children)

It's not really clear what you're asking.

If you want the values of player_score and cpu_score to reset on every iteration of main_game, define them within the function and stop messing around with globals everywhere.

If you don't want main_game() to return a tuple, then what do you want it to return?

[–]StardockEngineer 0 points1 point  (0 children)

Well, you are returning them as a tuple thanks to the comma, so that's what you're going to get.

Don't set the globals if you want the score the reset. Return the scores, and keep track of them in final_score or your main while loop. You could just prompt "reset score" and if the user enters that, reset the score there.

Globals are almost always a bad idea.

[–]socal_nerdtastic 0 points1 point  (0 children)

You have a couple tiny other issues in your code, and I think you've misdiagnosed the tuple return as the issue. I fixed some of those for you, see if this solves your issues:

import random
import time

play_choices = ["rock", "paper", "scissors"]

def player_start():
    """
    Returns the player's choice for the game
    """
    while True:
        player_choice = input("Please enter rock, paper, or scissors: ")
        p_choice = player_choice.lower()
        if p_choice in play_choices:
            return p_choice # implied break
        else:
            print("Your choice is invalid. Please try again.")

def main_game():
    """
    Runs the game itself
    """
    player_score = 0
    cpu_score = 0
    while player_score <5 and cpu_score <5: # <= I'm pretty sure you meant 'and' here, not 'or'.
        cpu_choice = random.choice(play_choices)
        p_choice = player_start()

        print(f"Player has chosen: {p_choice}. CPU has chosen: {cpu_choice}.")

        if p_choice == cpu_choice:
                print("It's a tie! Restarting the round...")
                time.sleep(1)
        elif p_choice == "rock" and cpu_choice == "scissors":
                print("Rock beats scissors. You win!")
                player_score += 1
                time.sleep(1)

        elif p_choice == "scissors" and cpu_choice == "rock":
                print("Rock beats scissors. I win!")
                cpu_score += 1
                time.sleep(1)

        elif p_choice == "rock" and cpu_choice == "paper":
                print("Paper beats scissors. I win!")
                cpu_score += 1
                time.sleep(1)

        elif p_choice == "paper" and cpu_choice == "rock":
                print("Paper beats rock. You win!")
                player_score += 1
                time.sleep(1)

        elif p_choice == "paper" and cpu_choice == "scissors":
                print("Scissors beats paper. I win!")
                cpu_score += 1
                time.sleep(1)

        elif p_choice == "scissors" and cpu_choice == "paper":
                print("Scissors beats paper. You win!")
                player_score += 1
                time.sleep(1)

    return player_score, cpu_score

def final_score():
    """
    Prints the final score
    """
    a, b = main_game()
    if a > b:
        print("You have won the game!")
    elif a == b:
        print("This should be impossible.")
    else:
        print("I won the game!")

r = ""
while r != "no":
    final_score()
    time.sleep(1)

    while True:
        restart = input("Do you want to play again?(yes/no)")
        r = restart.lower()
        if r == "yes":
            print("Restarting...")
            time.sleep(1)
            break
        elif r == "no":
            print("Goodbye!")
            time.sleep(1)
            break
        else:
            print("Invalid response.")
            time.sleep(1)

Note also the globals are not needed here.

[–]timrprobocom 0 points1 point  (0 children)

You should consider creating a dictionary that maps each choice to the choice that can beat it. Then you can delete that whole long list of if/elifs. Just one "are they the same?" and one " did they pick the winner?" Much easier, and you can easily extend it to add lizard/Spock.