Advertisement
biswasrohit20

rock

May 27th, 2021
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def show_rules():
  5. print('''Rules:
  6. Each player chooses either rock, paper, or scissors.
  7. The winner is determined by the following rules:
  8. rock smashes scissors -> rock wins
  9. scissors cuts paper paper covers rock -> scissors wins
  10. paper covers rock -> paper wins
  11. ''')
  12.  
  13.  
  14. def get_player_choice():
  15. player_choice = input("Player choice: ")
  16. return player_choice.lower()
  17.  
  18.  
  19. def get_computer_choice():
  20. num = random.randint(1,3)
  21. if num == 1:
  22. computer_choice = "rock"
  23. elif num == 2:
  24. computer_choice = "paper"
  25. elif num == 3:
  26. computer_choice = "scissors"
  27. print("Computer choice: " + computer_choice)
  28. print()
  29. return computer_choice
  30.  
  31.  
  32. def declare_winner(player, computer):
  33. if player == computer:
  34. print("Winner: Draw")
  35. elif player == "rock" and computer == "scissors":
  36. print("Winner: player")
  37. elif player == "rock" and computer == "paper":
  38. print("Winner: computer")
  39. elif player == "paper" and computer == "scissors":
  40. print("Winner: computer")
  41. elif player == "paper" and computer == "rock":
  42. print("Winner: player")
  43. elif player == "scissors" and computer == "rock":
  44. print("Winner: computer")
  45. elif player == "scissors" and computer == "paper":
  46. print("Winner: player")
  47.  
  48.  
  49. def play_game():
  50. show_rules()
  51. player = get_player_choice()
  52. computer = get_computer_choice()
  53. declare_winner(player, computer)
  54.  
  55.  
  56. play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement