0

I want to reset the code depending on user input like if yes reset the code if no stop it. I know it's a really bad code, sorry about that I am still learning :)

import random

tool = input("Choose your weapon (R)ock (P)aper (S)cissors ")

computer = random.choice(["Rock", "Paper", "Scissors"])

if tool == "R" and computer == "Paper":
    print("You lost aganist ",computer,"!")

elif tool == "R" and computer == "Scissors":
    print("You won aganist! ",computer,"!")

elif tool == "R" and computer == "Rock":
    print("That's a tie!")

elif tool == "P" and computer == "Rock":
    print("You won aganist ",computer,"!")

elif tool == "P" and computer == "Scissors":
    print("You lost aganist ",computer,"!")

elif tool == "P" and computer == "Paper":
    print("That's a tie!")

elif tool == "S" and computer == "Rock":
    print("You lost aganist ",computer,"!")

elif tool == "S" and computer == "Paper":
    print("You won aganist ",computer,"!")

elif tool == "S" and computer == "Scissors":
    print("That's a tie!")
Boody
  • 21
  • 3

1 Answers1

1

put it in a while loop and ask to repeat it, setting the bool to no if he says no. this is ignoring wrong inputs btw, you should check if his input is legal, like i did here

import random

playing = True

while playing:

    tool = input("Choose your weapon (R)ock (P)aper (S)cissors ")

    computer = random.choice(["Rock", "Paper", "Scissors"])

    if tool == "R" and computer == "Paper":
        print("You lost aganist ",computer,"!")

    #...

    elif tool == "S" and computer == "Scissors":
        print("That's a tie!")

    else:
        print("Wrong input! Sorry!")

    play_again = input("Do you want to play again? y/n")
    
    if (play_again == "n"):
        playing = False
        
Maritn Ge
  • 997
  • 8
  • 35