Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Paper Rock Scissors Game by #IT45200
- # Compatible only with Python 3.10 and Higher
- import random
- options = {"P": "Paper", "R": "Rock", "S": "Scissors"}
- name=input("Enter your name :")
- computer_score = 0
- player_score = 0
- game_on = True
- number_of_rounds=0
- winner = ""
- def display_scores():
- print("-------------------------")
- print("")
- print(f"Round N°: {number_of_rounds}")
- print("------ Score Board ------")
- print(f"{name}: {player_score} | Computer: {computer_score}")
- print("===============================")
- print("")
- def wins(x, y):
- match x+y:
- case "RS":
- return "C"
- case "SP":
- return "C"
- case "PR":
- return "C"
- case "SR":
- return "P"
- case "PS":
- return "P"
- case "RP":
- return "P"
- case _:
- return "N"
- while number_of_rounds < 5:
- computer_choice = random.choice(list(options.keys()))
- number_of_rounds += 1
- player_choice = input("Enter Paper(P), Rock(R) or Scissors(S): ")
- while True:
- if player_choice not in list(options.keys()):
- player_choice = input("Please choose a valid entry (P, R, S): ")
- else:
- break
- res = wins(computer_choice, player_choice)
- match res:
- case "C":
- computer_score += 1
- winner = "Computer"
- case "P":
- player_score += 1
- winner = name
- case _:
- winner = "Nobody"
- print(f"You chose {options.get(player_choice)}")
- print(f"Computer chose {options.get(computer_choice)}")
- display_scores()
- print(f"{winner} win this Round\n")
- if number_of_rounds == 5:
- game_on = False
- break
- if player_score == computer_score:
- print("Draw!!")
- elif player_score > computer_score:
- print(f"Congrats {name}, You won the game!!")
- else:
- print(f"Oops Computer won the game!! Better luck next time {name}!")
Advertisement
Add Comment
Please, Sign In to add comment