IT45200

Rocke Paper Scissors Game

Feb 25th, 2023 (edited)
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | Source Code | 0 0
  1. # Python Paper Rock Scissors Game by #IT45200
  2. # Compatible only with Python 3.10 and Higher
  3. import random
  4. options = {"P": "Paper", "R": "Rock", "S": "Scissors"}
  5. name=input("Enter your name :")
  6. computer_score = 0
  7. player_score = 0
  8. game_on = True
  9. number_of_rounds=0
  10. winner = ""
  11.  
  12. def display_scores():
  13.        print("-------------------------")
  14.        print("")
  15.        print(f"Round N°: {number_of_rounds}")
  16.        print("------ Score Board ------")
  17.        print(f"{name}: {player_score} | Computer: {computer_score}")
  18.        print("===============================")
  19.        print("")
  20.    
  21. def wins(x, y):
  22.     match x+y:
  23.         case "RS":
  24.             return "C"
  25.         case "SP":
  26.             return "C"          
  27.         case "PR":
  28.             return "C"
  29.         case "SR":
  30.             return "P"
  31.         case "PS":
  32.             return "P"          
  33.         case "RP":
  34.             return "P"
  35.         case _:
  36.             return "N"    
  37.  
  38. while number_of_rounds < 5:
  39.     computer_choice = random.choice(list(options.keys()))
  40.     number_of_rounds += 1
  41.     player_choice = input("Enter Paper(P), Rock(R) or Scissors(S): ")
  42.     while True:
  43.             if player_choice not in list(options.keys()):
  44.                 player_choice = input("Please choose a valid entry (P, R, S): ")
  45.                
  46.             else:
  47.                 break            
  48.     res = wins(computer_choice, player_choice)
  49.     match res:
  50.         case "C":
  51.             computer_score += 1
  52.             winner = "Computer"      
  53.         case "P":
  54.             player_score += 1
  55.             winner = name    
  56.         case _:
  57.             winner = "Nobody"
  58.     print(f"You chose {options.get(player_choice)}")    
  59.     print(f"Computer chose {options.get(computer_choice)}")
  60.     display_scores()
  61.     print(f"{winner} win this Round\n")
  62.     if number_of_rounds == 5:
  63.         game_on = False
  64.         break
  65.    
  66. if player_score == computer_score:
  67.   print("Draw!!")
  68. elif player_score > computer_score:
  69.   print(f"Congrats {name}, You won the game!!")
  70. else:
  71.   print(f"Oops Computer won the game!! Better luck next time {name}!")
  72.    
  73.    
Advertisement
Add Comment
Please, Sign In to add comment