Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def show_rules():
- print('''Rules:
- Each player chooses either rock, paper, or scissors.
- The winner is determined by the following rules:
- rock smashes scissors -> rock wins
- scissors cuts paper paper covers rock -> scissors wins
- paper covers rock -> paper wins
- ''')
- def get_player_choice():
- player_choice = input("Player choice: ")
- return player_choice.lower()
- def get_computer_choice():
- num = random.randint(1,3)
- if num == 1:
- computer_choice = "rock"
- elif num == 2:
- computer_choice = "paper"
- elif num == 3:
- computer_choice = "scissors"
- print("Computer choice: " + computer_choice)
- print()
- return computer_choice
- def declare_winner(player, computer):
- if player == computer:
- print("Winner: Draw")
- elif player == "rock" and computer == "scissors":
- print("Winner: player")
- elif player == "rock" and computer == "paper":
- print("Winner: computer")
- elif player == "paper" and computer == "scissors":
- print("Winner: computer")
- elif player == "paper" and computer == "rock":
- print("Winner: player")
- elif player == "scissors" and computer == "rock":
- print("Winner: computer")
- elif player == "scissors" and computer == "paper":
- print("Winner: player")
- def play_game():
- show_rules()
- player = get_player_choice()
- computer = get_computer_choice()
- declare_winner(player, computer)
- play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement