1

I am trying to increase the value of the variable called "round" by 1 each time it loops, but the variable always show 2 and continues to show 2 each time the loop runs.

round = 1
if quitGame == "N":
         break
    else:
        round += 1
        print(f"Round({round})")

I don't know what to do at this point.

Here is the full code...

from random import random, randint
import random

running = True
global p_wins,p_losses,p_draws,c_wins,c_losses,c_draws
p_wins = 0
p_losses = 0
p_draws = 0
c_wins = 0
c_losses = 0
c_draws = 0

print("=====Rock Paper Scissors: The Python Game=====")
print("\n")
name = input("Player please enter you name:\n")
print("\n")
print("\n")

while running == True:
    
#Point System
    def Score():

        print("====Player's Score====")
        print(f"Wins:{p_wins}")
        print(f"Losses:{p_losses}")
        print(f"Draws:{p_draws}")

        print("====CPU's Score====")
        print(f"Wins:{c_wins}")
        print(f"Losses:{c_losses}")
        print(f"Draws:{c_draws}")

    if len(name) > 12:
        print("Player's name is TOO long")
        break

    myItem = input("Enter Either Rock Paper or Scissors:\n")
    print("\n")
    print(f"{name} chooses {myItem}...")


    if myItem not in ("Rock","Paper","Scissors"):
       print("Are you Ok!! I said enter rock paper or scissors")
       print("GAME OVER!!!!!!")
       break
    

#Computer's Choices
    computerItem = random.randint(1,3)
    if computerItem == 1:
        computerItem = "Rock"
        print(f"Computer chooses {computerItem}...")
    if computerItem == 2:
        computerItem = "Paper"
        print(f"Computer chooses {computerItem}...")
    if computerItem == 3:
        computerItem = "Scissors"
        print(f"Computer chooses {computerItem}...")


    if myItem == computerItem:
        print("Try Again!! You and the CPU picked the same thing")
        p_draws += 1
        c_draws += 1
        Score()
        

#Game Rules
    if myItem == "Rock" and computerItem == "Paper":
        print("[Paper covers Rock]")
        print("CPU WINS!!!")
        p_losses += 1
        c_wins += 1
        Score()
        
    if myItem == "Paper" and computerItem == "Rock":
        print("[Paper covers Rock]")
        print(f"{name} WINS!!!")
        p_wins += 1
        c_losses += 1
        Score()

    if myItem == "Scissors" and computerItem == "Rock":
        print("[Rock Smashes Scissors]")
        print("CPU WINS!!!")
        p_losses += 1
        c_wins += 1
        Score()
        
    if myItem == "Rock" and computerItem == "Scissors":
        print("[Rock smashes Scissors]")
        print(f"{name} WINS!!!")
        p_wins += 1
        c_losses += 1
        Score()
        

    if myItem == "Paper" and computerItem == "Scissors":
        print("[Scissors cut Paper]")
        print("CPU WINS!!!")
        p_losses += 1
        c_wins += 1
        Score()
        

    if myItem == "Scissors" and computerItem == "Paper":
        print("[Scissors cut Paper]")
        print(f"{name} WINS!!!")
        p_wins += 1
        c_losses += 1
        Score()
        
    round = 1
    quitGame = input("Do you want to continue playing (Y/N):\n")

    if quitGame == "N":
         break
    else:
        round += 1
        print(f"Round({round})")

For context, I am making a rock, paper, scissors game using python. I want to print the print "Round(num)" every time a new round has begun but it just isn't working.

1 Answer 1

1

You are declaring the variable inside the loop. So at each iteration the value is set to 1 again and increment 1, forever.

Like this:

for i in [1,2]:
   a = 1
   a +=1
   print (a) # 2

But that is different of:

a = 1    
for i in [1,2]:
   a +=1
   print (a) # 2
Sign up to request clarification or add additional context in comments.

Comments

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.