Skip to content

Instantly share code, notes, and snippets.

@mburakerman
Last active July 6, 2020 09:53
Show Gist options
  • Save mburakerman/cce61bc1dd1f56e120e7f221e76713a2 to your computer and use it in GitHub Desktop.
Save mburakerman/cce61bc1dd1f56e120e7f221e76713a2 to your computer and use it in GitHub Desktop.
python rock-scissors-paper game
import random
game = ["rock", "scissors", "paper"]
human_val = False
print("enter rock, scissors or paper")
while human_val == False:
human_val = input()
computer_val = random.choice(game)
print(f"πŸ’» computer: {computer_val}")
# check if valid
if human_val not in game:
print("please type rock, scissors or paper correctly\n")
if human_val == computer_val:
print("tie\n")
# rock
elif human_val == "rock":
if computer_val == "scissors":
print("πŸŽ‰ you win!\n")
elif computer_val == "paper":
print("πŸŽ‰ computer wins!\n")
# scissors
elif human_val == "scissors":
if computer_val == "rock":
print("πŸŽ‰ computer wins!\n")
elif computer_val == "paper":
print("πŸŽ‰ you win!\n")
# paper
elif human_val == "paper":
if computer_val == "rock":
print("πŸŽ‰ you win!\n")
elif computer_val == "scissors":
print("πŸŽ‰ computer wins!\n")
human_val = False
computer_val = random.choice(game)
print("enter rock, scissors or paper")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment