2

I wanted to make a simple Rock, Paper, Scissor game in Python. It goes well with the game, but the final scores are always being showed as a 0.

I wanted to show a smaller section of the code but, I don't know where the problem lies, so I am sorry for the length of the code.

I am still a novice learner, so please pardon me if the question is too silly or the code is not well formatted.

#Rock-Paper-Scissor Game
import random


print("Please enter your name:")
userName = input()
print("Welcome " + userName)
print("The following are the rules of the game:")
print("Press 'R' for Rock")
print("Press 'P' for Paper")
print("Press 'S' for Scissor")
print("This will be a 10 point match")

userTally = 0
compTally = 0

def gameProcess(userTally, compTally): #The process of the game. It increments or decrements the value depending on the result
    print("Your turn:")
    userInput = input()
    computerChoice = random.choice(["R","P","S"])

    if userInput == "R": #User Inputs R for Rock

        if computerChoice == "R":
            print("The computer chose Rock")
            print("It's a Tie")
        elif computerChoice == "P":
            print("The computer chose Paper")
            print("Computer Won")
            compTally = compTally + 1
        elif computerChoice == "S":
            print("The computer chose Scissor")
            print("You Won")
            userTally = userTally + 1

    elif userInput == "P": #User Inputs P for Paper

        if computerChoice == "R":
            print("The computer chose Rock")
            print("You Won")
            userTally = userTally + 1
        elif computerChoice == "P":
            print("The computer chose Paper")
            print("It's a Tie")
        elif computerChoice == "S":
            print("The computer chose Scissor")
            print("Computer Won")
            compTally = compTally + 1

    elif userInput == "S": #User Inputs S for Scissor

        if computerChoice == "R":
            print("The computer chose Rock")
            print("Computer Won")
            compTally = compTally + 1
        elif computerChoice == "P":
            print("The computer chose Paper")
            print("You Won")
            userTally = userTally + 1
        elif computerChoice == "S":
            print("The computer chose Scissor")
            print("It's a Tie")
        return(userTally,compTally)

def tryCount(): #The number of tries....
    tryNum = 1
    while tryNum < 11:

        gameProcess(0, 0)
        tryNum = tryNum + 1

tryCount()


print("You scored " + str(userTally))
print("The computer scored " + str(compTally))
if userTally > compTally:
    print("CONGRATULATIONS, YOU WON.")
elif userTally < compTally:
    print("Sorry, better luck next time.")
close = input()
if close == "Random Input.":
    exit()
else:
    exit()
1
  • 1
    The return in the gameProcess is wrongly indented, it should not be part of the elif block. Commented Dec 31, 2018 at 14:11

1 Answer 1

2

You pass 0, 0 to gameProcess, which you treat as the scores within the function, and then return them modified, but you do not actually use the return value in the only place you call gameProcess (in tryCount), so the global userTally, compTally variables remain unchanged.

This is how you should change tryCount:

def tryCount(): #The number of tries....
    global userTally, compTally
    tryNum = 1
    while tryNum < 11:

        userTally,compTally=gameProcess(userTally,compTally)
        tryNum = tryNum + 1
Sign up to request clarification or add additional context in comments.

4 Comments

So, what should I change here. By the way, thanks for pointing out the problem.
Edited answer. Also you need to fix the return in gameProcess, as a_guest pointed it out.
I tried making the above changes and also fixed the return in gameProcess, but now it just takes the last value of the 10 chances and gives the output based on that like 'if I won the last chances it shows "you scored 1 " irrespective of the previous chances.
Right, my bad. Edited again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.