Help with adding loop to code

Question:
How can I add a loop to my code? I am very confused on which kind of loop to add and how to embed it in my code. PLease help.

import random

print("Thank You for choosing to play Rock, Paper, Scissors UPGRADED.          Welcome to Asteroid, Super Blanket, Sword!                          Choose your move!")
Player_score=0
Computer_score=0 

user = input("Asteroid, Super Blanket, or Sword?") 
computer = random.choice(["Asteroid","Super Blanket", "Sword"])

if user == computer: 
     print("You and the AI tied!")
elif user == "Super Blanket":
    if computer == "Sword":
      print("AI chose the Sword, The Sword cuts the Super Blanket, You Lose!")  
      Computer_score= +1
    else:
      print("AI chose the Asteroid, The Super Blanket wraps up the Asteroid,       You Win!") 
      Player_score = +1
elif user == "Sword":
      if computer == "Asteroid":
        print("AI chose the Asteroid, The Asteroid crushes the Sword,  You Lose!")
        Computer_score= +1
      else:
        print("AI chose the Super Blanket, The Sword cuts the Super Blanket, You Win!") 
        Player_score = +1
elif user == "Asteroid":
  if computer == "Super Blanket":
    print("AI chose the Super Blanket, The Super Blanket wraps up the Asteroid,  You Lose!") 
    Computer_score= +1
  else:
    print("AI chose the Sword, The Asteroid crushes the Sword, You Win!") 
  Player_score = +1


Player_score 
Computer_score

num_games = 1
for i in range(num_games):
  
  print("Your score:", Player_score)
print("Computer score:", Computer_score)
1 Like

You can do a while True loop that runs indefinitely, or you can do what you did, which was a for loop, in which case your sample code would be:

While True:

import random

print(
    "Thank You for choosing to play Rock, Paper, Scissors UPGRADED.          Welcome to Asteroid, Super Blanket, Sword!                          Choose your move!"
)
Player_score = 0
Computer_score = 0

while True:
    user = input("Asteroid, Super Blanket, or Sword?")
    computer = random.choice(["Asteroid", "Super Blanket", "Sword"])
    if user == computer:
        print("You and the AI tied!")
    elif user == "Super Blanket":
        if computer == "Sword":
            print("AI chose the Sword, The Sword cuts the Super Blanket, You Lose!")
            Computer_score = +1
        else:
            print(
                "AI chose the Asteroid, The Super Blanket wraps up the Asteroid,       You Win!"
            )
            Player_score = +1
    elif user == "Sword":
        if computer == "Asteroid":
            print("AI chose the Asteroid, The Asteroid crushes the Sword,  You Lose!")
            Computer_score = +1
        else:
            print(
                "AI chose the Super Blanket, The Sword cuts the Super Blanket, You Win!"
            )
            Player_score = +1
    elif user == "Asteroid":
        if computer == "Super Blanket":
            print(
                "AI chose the Super Blanket, The Super Blanket wraps up the Asteroid,  You Lose!"
            )
            Computer_score = +1
        else:
            print("AI chose the Sword, The Asteroid crushes the Sword, You Win!")
            Player_score = +1

For:

import random

print(
    "Thank You for choosing to play Rock, Paper, Scissors UPGRADED.          Welcome to Asteroid, Super Blanket, Sword!                          Choose your move!"
)
Player_score = 0
Computer_score = 0

for _ in range(6):
    user = input("Asteroid, Super Blanket, or Sword?")
    computer = random.choice(["Asteroid", "Super Blanket", "Sword"])
    if user == computer:
        print("You and the AI tied!")
    elif user == "Super Blanket":
        if computer == "Sword":
            print("AI chose the Sword, The Sword cuts the Super Blanket, You Lose!")
            Computer_score = +1
        else:
            print(
                "AI chose the Asteroid, The Super Blanket wraps up the Asteroid,       You Win!"
            )
            Player_score = +1
    elif user == "Sword":
        if computer == "Asteroid":
            print("AI chose the Asteroid, The Asteroid crushes the Sword,  You Lose!")
            Computer_score = +1
        else:
            print(
                "AI chose the Super Blanket, The Sword cuts the Super Blanket, You Win!"
            )
            Player_score = +1
    elif user == "Asteroid":
        if computer == "Super Blanket":
            print(
                "AI chose the Super Blanket, The Super Blanket wraps up the Asteroid,  You Lose!"
            )
            Computer_score = +1
        else:
            print("AI chose the Sword, The Asteroid crushes the Sword, You Win!")
            Player_score = +1

You need to put all of the code for your game into the loop so the game itself is actually looping. Right now you are just looping printing out the player’s score.

1 Like

Sorry i was wrong with my previous response, i misunderstood the question.

To put the game in a loop just put the entire code in a “while True” loop

while True:
     //code

i would also recommend importing os

import os

this way at the end of the code you can delete avery thing on screen

system.os("clear")
1 Like

Why import stuff when you can use this?

clear = lambda: print('\033c' end='' flush=True)
clear()
2 Likes