Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with keeping score
#1
Hi. I am new to the forums and Python in general. I have made a "simple" rock, paper, scissors game and am trying to keep a running score. Basically, what is in the code is what I've tried. I added the while loop at the beginning of the def Game() function because I thought that it was due to the reset I had going when the user restarts as to why the score was not saving.

All in all, I want a running score of wins, losses, and draws from the player.

The code is as follows:

import random
import sys



def Game():
    while True:

        comp = random.randint(1,3)
        win = "\nYou WIN!!!"
        lost = "\nYou lost."
        draw = "\nIt's a draw."

#Beginning statement#
        print("\nWelcome to Rock, Paper, Scissors!\nYour opponent is me, the computer!\n")
        choice = int(input("Please choose your weapon by choosing a number!\n1. Rock\n2. Paper\n3. Scissors\n"))

        list = [comp,choice]
        wr = 0
        lr = 0
        dr = 0


#Win/Loss/Draw if statement#
        if list == [1,2]:
            print(win)
            wr = wr + 1
        elif list == [1,3]:
            print(lost)
            lr += 1
        elif list == [1,1]:
            print(draw)
            dr += 1
        elif list == [2,1]:
            print(lost)
            lr += 1
        elif list == [2,2]:
            print(draw)
            dr += 1
        elif list == [2,3]:
            print(win)
            wr = wr + 1
        elif list == [3,1]:
            print(win)
            wr = wr + 1
        elif list == [3,2]:
            print(lost)
            lr += 1
        elif list == [3,3]:
            print(draw)
            dr += 1
        else:
            print("Please choose a listed number.")
            continue
        
#Score shown#
        print("\nWins =", wr)
        print("Losses =", lr)
        print("Draws =", dr, "\n")

#Player's choice shown#
        if choice == 1:
            playerChoice = "Rock"
            print("\nYou chose", playerChoice)
        if choice == 2:
            playerChoice = "Paper"
            print("\nYou chose", playerChoice)
        if choice == 3:
            playerChoice = "Scissors"
            print("\nYou chose", playerChoice)


#Computer's choice shown#
        if comp == 1:
            compChoice = "Rock"
            print("\nI chose", compChoice)
        if comp == 2:
            compChoice = "Paper"
            print("\nI chose", compChoice)
        if comp == 3:
            compChoice = "Scissors"
            print("\nI chose", compChoice)

        
#Play Again#
        again = input("\nPlay again? Y/N\n")
        if again.upper() == "Y":
            continue
        else:
            print("\nThanks for playing!!")
            break
            sys.exit

        
Game()
Any help/criticism is appreciated.
Thanks.
Reply
#2
        wr = 0
        lr = 0
        dr = 0
You set those values back to 0 with each loop iteration. To keep the scores place them before the while loop, so they only get assigned 0 initially.
Reply
#3
Thank you. I will try that.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Keeping up with IDEs and Virtual Environments... bytecrunch 7 2,363 Sep-05-2022, 08:04 PM
Last Post: snippsat
  Keeping a value the same despite changing the variable it was equated to TheTypicalDoge 2 1,433 Mar-13-2022, 10:50 PM
Last Post: Yoriz
  Problem keeping the window up benlyboy 11 4,009 Jan-24-2020, 02:12 AM
Last Post: tamilselvisubbiah
  merging lists, dedup and keeping order, in older pythons Skaperen 3 3,100 Oct-19-2018, 01:30 AM
Last Post: ODIS
  Keeping Intersection of an Image Only Anysja 4 2,906 Aug-15-2018, 09:47 PM
Last Post: Anysja

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020