Check out above post here - Instagram
Code :
import random
while True:
choices=["rock","paper","scissors"]
computer=random.choice(choices)
player =None #None used to define a null value
while player not in choices:
player=input("Rock, Paper, or Scissors? : ").lower() #lowercase the string
if player==computer:
print("Computer :",computer)
print("Player : ",player)
print("Tie!!")
elif player=="rock":
if computer=="paper":
print("Computer :",computer) #paper
print("Player : ",player) #rock
print("You Lose!!")
else:
print("Computer :",computer) #scissors
print("Player : ",player) #rock
print("You Win!!")
elif player=="paper":
if computer=="rock":
print("Computer :",computer) #rock
print("Player : ",player) #paper
print("You Win!!")
else:
print("Computer :",computer) #scissors
print("Player : ",player) #paper
print("You Lose!!")
else:
if computer=="paper":
print("Computer :",computer) #paper
print("Player : ",player) #scissors
print("You Win!!")
else:
print("Computer :",computer) #rock
print("Player : ",player) #scissors
print("You Lose!!")
play_again=input("Play Again (yes/no): ").lower()
if play_again!="yes": #this will break the while loop
break
print("Game Over")
Output :
Comments
Post a Comment