Advertisement
BhuwanPanta

Untitled

Sep 2nd, 2024
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. from random import randint
  2.  
  3.  
  4. game_rules = {
  5.     "rock": ["scissors"],
  6.     "paper": ["rock"],
  7.     "scissors": ["paper"],
  8. }
  9.  
  10.  
  11. def game(user_move):
  12.     game_moves = list(game_rules.keys())
  13.     if user_move not in game_moves:
  14.         return "Invalid Move"
  15.     computer_move = game_moves[randint(0, 2)]  # computer move
  16.     print(f"{user_move=},{computer_move=}")
  17.     if user_move == computer_move:
  18.         return "draw"
  19.     if computer_move in game_rules[user_move]:
  20.         return "win"
  21.     else:
  22.         return "lose"
  23.  
  24.  
  25. print(game("scissors"))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement