+1 (315) 557-6473 

Python Program to Create Rock Paper Scissor Game Assignment Solution.


Instructions

Objective
Write a python assignment program to create rock paper scissor game.

Requirements and Specifications

Rock paper scissors game is also known as stone paper scissors. It is a hand game that is usually played between 2 people, each player can randomly form any one of three from their hand.
A player who chooses rock will win by another player who chooses scissors but loose by the player who chooses paper; a player with paper will loose by the player with the scissors.
If both players choose the same then the game is tied. Rock paper scissors game is mainly played among kids.
Rock-Paper-Scissors Game Python Project
The object of the rock-paper-scissor python project is to build a game for a single player that plays with a computer, anywhere, and anytime. This project is base on the rules that:
  • rock blunts scissors so rock wins
  • scissors cut the paper so scissors win
  • paper cover rock so paper wins
This project is build using tkinter, random modules, and the basic concept of python.
In this python project, players have to choose any one from rock, paper, and scissors. Then click on the play button will show the result of the game.
Project Prerequisites
To implement this python rock paper scissors project we will use the basic concept of python with tkinter and random module.
  • Tkinter is a standard GUI library which is one of the easiest ways to build a GUI application.
  • random module use to generate random numbers

Source Code

from tkinter import *

import random

root = Tk()

root.geometry('400x400')

root.resizable(0,0)

root.title('DataFlair-Rock,Paper,Scissors')

root.config(bg ='seashell3')

Label(root, text = 'Rock, Paper ,Scissors' , font='arial 20 bold', bg =

'seashell2').pack()

user_take = StringVar()

Label(root, text = 'choose any one: rock, paper ,scissors' , font='arial

15 bold', bg = 'seashell2').place(x = 20,y=70)

Entry(root, font = 'arial 15', textvariable = user_take , bg =

'antiquewhite2').place(x=90 , y = 130)

comp_pick = random.randint(1,3)

if comp_pick == 1:

comp_pick = 'rock'

elif comp_pick ==2:

comp_pick = 'paper'

else:

comp_pick = 'scissors'

Result = StringVar()

def play():

user_pick = user_take.get()

if user_pick == comp_pick:

Result.set('tie,you both select same')

elif user_pick == 'rock' and comp_pick == 'paper':

Result.set('you loose,computer select paper')

elif user_pick == 'rock' and comp_pick == 'scissors':

Result.set('you win,computer select scissors')

elif user_pick == 'paper' and comp_pick == 'scissors':

Result.set('you loose,computer select scissors')

elif user_pick == 'paper' and comp_pick == 'rock':

Result.set('you win,computer select rock')

elif user_pick == 'scissors' and comp_pick == 'rock':

Result.set('you loose,computer select rock')

elif user_pick == 'scissors' and comp_pick == 'paper':

Result.set('you win ,computer select paper')

else:

Result.set('invalid: choose any one -- rock, paper, scissors')

def Reset():Result.set("")

user_take.set("")

def Exit():

root.destroy()

Entry(root, font = 'arial 10 bold', textvariable = Result, bg

='antiquewhite2',width = 50,).place(x=25, y = 250)

Button(root, font = 'arial 13 bold', text = 'PLAY' ,padx =5,bg

='seashell4' ,command = play).place(x=150,y=190)

Button(root, font = 'arial 13 bold', text = 'RESET' ,padx =5,bg

='seashell4' ,command = Reset).place(x=70,y=310)

Button(root, font = 'arial 13 bold', text = 'EXIT' ,padx =5,bg

='seashell4' ,command = Exit).place(x=230,y=310)

root.mainloop()