Rock Paper Scissors Game using Python - Beyond Coding !



Introduction :

Rock Paper Scissors (also known by other orderings of the three items, with "rock" sometimes being called "stone", or as Rochambeau, roshambo, or ro-sham-bo) is a hand game originating from China, usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. 
These shapes are "rock" (a closed fist), "paper" (a flat hand), and "scissors" (a fist with the index finger and middle finger extended, forming a V). "Scissors" is identical to the two-fingered V sign (also indicating "victory" or "peace") except that it is pointed horizontally instead of being held upright in the air.
A simultaneous, zero-sum game, it has three possible outcomes: a draw, a win, or a loss. A player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors" or "breaks scissors" or sometimes "blunts scissors"), but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cuts paper"). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.
Rock Paper Scissors is often used as a fair choosing method between two people, similar to coin flipping, drawing straws, or throwing dice in order to settle a dispute or make an unbiased group decision. Unlike truly random selection methods, however, rock paper scissors can be played with a degree of skill by recognizing and exploiting non-random behavior in opponents.

There are two methods of making this game :

import random player1 = input("Select Rock, Paper, or Scissor :").lower() player2 = random.choice(["Rock", "Paper", "Scissor"]).lower() print("Player 2 selected: ", player2) if player1 == "rock" and player2 == "paper": print("Player 2 Won") elif player1 == "paper" and player2 == "scissor": print("Player 2 Won") elif player1 == "scissor" and player2 == "rock": print("Player 2 Won") elif player1 == player2: print("Tie") else: print("Player 1 Won")

Output :





import random import tkinter stats = [] def get_winner(call): if random.random() <= (1 / 3): throw = "rock" elif (1 / 3) < random.random() <= (2 / 3): throw = "scissors" else: throw = "paper" if (throw == "rock" and call == "paper") or (throw == "paper" and call == "scissors") \ or (throw == "scissors" and call == "rock"): stats.append('W') result = "You won!" elif throw == call: stats.append('D') result = "It's a draw" else: stats.append('L') result = "You lost!" global output output.config(text="Computer did: " + throw + "\n" + result) def pass_s(): get_winner("scissors") def pass_r(): get_winner("rock") def pass_p(): get_winner("paper") window = tkinter.Tk() scissors = tkinter.Button(window, text="Scissors", bg="#ff9999", padx=10, pady=5, command=pass_s, width=20) rock = tkinter.Button(window, text="Rock", bg="#80ff80", padx=10, pady=5, command=pass_r, width=20) paper = tkinter.Button(window, text="Paper", bg="#3399ff", padx=10, pady=5, command=pass_p, width=20) output = tkinter.Label(window, width=20, fg="red", text="What's your call?") scissors.pack(side="left") rock.pack(side="left") paper.pack(side="left") output.pack(side="right") window.mainloop() for i in stats: print(i, end=" ") if stats.count('L') > stats.count('W'): result = "\nYou loose the series." elif stats.count('L') == stats.count('W'): result = "\nSeries ended in a draw." else: result = "\nYou win the series." print(result)


Output :


Comments