simple python rock paper scissors code example
Example 1: python rock paper scissors
import random
game_list = ['Rock', 'Paper', 'Scissors']
computer = c = 0
command = p = 0
print("Score: Computer" + str(c) + " Player " + str(p))
# the loop
run = True
while run:
computer_choice = random.choice(game_list)
command = input("Rock, Paper, Scissors or Quit: ")
if command == computer_choice:
print("Tie")
elif command == 'Rock':
if computer_choice == 'Scissors':
print("Player won!")
p += 1
else:
print("Computer won!")
c += 1
elif command == 'Paper':
if command == 'Rock':
print("Player won!")
p += 1
else:
print("Computer won!")
c += 1
elif command == 'Scissors':
if computer_choice == 'Paper':
print("Player won!")
p += 1
else:
print("Computer won!")
c += 1
elif command == 'Quit':
break
else:
print("Wrong command! ")
print("Player: " + command)
print("Computer: " + computer_choice)
print("")
print("Score: Computer " + str(c) + " Player " + str(p))
print("")
Example 2: python rock paper scissors
from random import randint
userA = input("Rock(R), Paper(P) or Scissors(S)")
comp = ["R", "P", "S"]
compA = comp[randint(0, 2)]
if userA == compA:
print("Draw")
elif userA == "R" and compA == "P":
print("You Lose")
elif userA == "R" and compA == "S":
print("You Win")
elif userA == "S" and compA == "P":
print("You Win")
elif userA == "S" and compA == "R":
print("You Lose")
elif userA == "P" and compA == "R":
print("You Win")
elif userA == "P" and compA == "S":
print("You Lose")
else:
print("ERROR")