0

Any way to repeat an if loop in python?

Trying my code and I have to ask user to run it again instead of getting another input. Any Suggestions? I will post my code in the comments.

29th Jan 2017, 1:36 PM
DerpyOmnister
DerpyOmnister - avatar
3 odpowiedzi
0
import random #Chooses random play for the computer Computer = random.choice(["Rock", "Paper", "Scissors"]) #Ask The player for it's input User = input("Choose: Rock/Paper/Scissors: ") User = User.lower() User = User.strip() #Get all of the Results and Specify what it should say if User == Computer: print("Computer chose: " + str(Computer)) print("Player chose: " + str(User)) print("It's A Draw!") elif User == "rock": if Computer == "Paper": print("\nComputer Chose: " + str(Computer)) print("Player Chose: " + str(User)) print("The Computer Wins!") else: print("\nComputer Chose: " + str(Computer)) print("Player Chose: " + str(User)) print("The Player Wins!") elif User == "paper": if Computer == "Scissors": print("\nComputer Chose: " + str(Computer)) print("Player Chose: " + str(User)) print("The Computer Wins!") else: print("\nComputer Chose: " + str(Computer)) print("Player Chose: " + str(User)) print("The Player Wins!") elif User == "scissors": if Computer == "Rock": print("\nComputer Chose: " + str(Computer)) print("Player Chose: " + str(User)) print("The Computer Wins!") else: print("\nComputer Chose: " + str(computer)) print("Player Chose: " + str(User)) print("The Player Wins!") elif User == "yoda": print("\nNice Job Finding Secret, Young Padawan!") print("The Force controls You!") print("\nAlso, you would've won that game any way") else: print("\nI Didn't Understand You,") print("Try Running it again.")
29th Jan 2017, 1:36 PM
DerpyOmnister
DerpyOmnister - avatar
0
while True: # your code here test = input(" New Game (y/n) ? ") If test == "n": break
29th Jan 2017, 2:14 PM
Jhonnatha Andrade
Jhonnatha Andrade - avatar
0
Thx a ton homie
30th Jan 2017, 3:34 PM
DerpyOmnister
DerpyOmnister - avatar