• How it works
  • Homework answers

Physics help

Answer to Question #164741 in Python for prathyusha

Given a string of length N, made up of only uppercase characters 'R' and 'G', where 'R' stands for Red and 'G' stands for Green. Find out the minimum number of characters you need to change to make the whole string of the same colour.

Need a fast expert's response?

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS !

Leave a comment

Ask your question, related questions.

  • 1. Temperature ConversionYou are given the temperature T of an object in one of Celsius, Fahrenheit, an
  • 2. Abhinav and Anjali are playing Rock-Paper-Scissors game. Rock-Paper-Scissors is a hand game usually
  • 3. Describe the difference between a chained conditional and a nested conditional. Give your own exampl
  • 4. Given a string of length N, made up of only uppercase characters 'R' and 'G', wh
  • 5. Describe the difference between a chained conditional and a nested conditional. Give your own exampl
  • 6. Write the substitutionDecrypt method. Test your algorithm as shown below. Your code should work for
  • 7. The transposition cipher can be generalized to any number of rails. Write a function to implement a
  • Programming
  • Engineering

10 years of AssignmentExpert

Who Can Help Me with My Assignment

There are three certainties in this world: Death, Taxes and Homework Assignments. No matter where you study, and no matter…

How to finish assignment

How to Finish Assignments When You Can’t

Crunch time is coming, deadlines need to be met, essays need to be submitted, and tests should be studied for.…

Math Exams Study

How to Effectively Study for a Math Test

Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…

  • Free Python 3 Tutorial
  • Control Flow
  • Exception Handling
  • Python Programs
  • Python Projects
  • Python Interview Questions
  • Python Database
  • Data Science With Python
  • Machine Learning with Python

hand game in python assignment expert

  • Explore Our Geeks Community
  • pytwisty: Rubik's Cube Solver - Python Project
  • GUI Billing System and Menu Card Using Python
  • Pollution Control by Identifying Potential Land for Afforestation - Python Project
  • Restaurant Review Analysis Using NLP and SQLite
  • Twitter Sentiment Analysis WebApp Using Flask
  • Facts App Using Tkinter module
  • Human Scream Detection and Analysis for Controlling Crime Rate - Project Idea
  • Turing Machine Simulator Using Python
  • IPL Score Prediction using Deep Learning
  • College Management System using Django - Python Project
  • E-commerce Website using Django
  • Multilingual Google Meet Summarizer - Python Project
  • Project Idea - Searching news from Old Newspaper using NLP
  • HAUS Connect - Python Project
  • Online Schooling System - Python Project
  • Project Idea - Algorithmic Trading Bot
  • Project Idea | Traverse Indoor (Gene Reader App)
  • Personalized Task Manager in Python
  • Visualize Merge sort Using Tkinter in Python

Rock, Paper, Scissor game – Python Project

In this article, we will see how we can create a rock paper and scissor game using Tkinter. Rock paper scissor is a hand game usually played between two people, in which each player simultaneously forms one of the three shapes with an outstretched hand. These shapes are “rock”, “paper”, and “scissors”.

Game Winner Conditions

Let there be a Player who is playing with a computer as an opponent.  Now,

  • If the player selects Paper and Computer Selects Scissor – Computer wins
  • If the player selects Rock and Computer Selects Scissor – Player 1 wins
  • If the player selects Paper and Computer Selects Rock – Player 1 wins
  • And If the player selects Paper and Computer Selects Paper – Draw
  • If the player selects Rock and Computer Selects Rock – Draw
  • If the player selects Scissor and Computer Selects Scissor – Draw

Tools and Technologies Used

  • Tkinter: It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create GUI applications.
  • Random: Python defines a set of functions that are used to generate or manipulate random numbers through the random module.
  • PIL: Python Imaging Library (expansion of PIL) is the de facto image processing package for Python language. It incorporates lightweight image processing tools that aids in editing, creating and saving images.

GUI Implementation 

Part 1: image processing and handling.

1) Import Python Module Tkinter to execute GUI applications.

2) From PIL Import ImageTk, Image for image processing.

3) Import random which will help the computer to select options rock, paper, or scissor randomly.

4) Now an object is created root which is the main window object.

  • Title of this window -> Rock Paper Scissor
  • Dimensions of this window -> “800×680”

5) Create canvas of width=800, height=680

6) Now we Create labels on GUI window

  • l1 =Player-> font=’Algerian’, size=25
  • l2 =Computer-> font=’Algerian’, size=25
  • l3 =Vs font=’Algerian’, size=40

7) Now labels are placed on window

  • l1 at x=80, y=20
  • l2 at x=560, y=20
  • l3 at x=370, y=230

For Default Image:

1) An variable named img_p is used to open the default hand image and resize it to (300,300). This will be shown at default condition in the game at the place of the player.

2) An variable named img_c is used to store flipped default image from left to right using transpose function and it is saved in the variable. This will be shown at default condition in the game at the place of the computer’s side.

3) Images img_p and img_c are loaded on the canvas now using Tk.PhotoImage

For Rock Image:

1) An variable named rock_p is used to open the rock hand image and resize it to (300,300). This will be shown at the player’s side when the player selects rock in the game.

2) An variable named rock_c is used to store flipped rock hand image from left to right using transpose function and will be shown at computer’s side when the computer randomly selects rock in the game.

3) Images rock_p and  rock_c are loaded on the canvas now using Tk.PhotoImage.

For Paper Image

1) An variable named paper_p is used to open the paper hand image and resize it to (300,300). This will be shown at the player’s side when the player selects paper in the game.

2) An variable named paper_c is used to store flipped paper hand images from left to right using the transpose function and will be shown at the computer’s side when the computer randomly selects paper in the game.

3) Images paper_p and  paper_c is loaded on the canvas now using Tk.PhotoImage.

For Scissors Image

1) An variable named scissor_p is used to open the scissor hand image and resize it to (300,300). This will be shown at player’s side when player selects scissor in the game.

2) An variable named scissor_c is used to store flipped scissor hand image from left to right using transpose function and will be shown at computer’s side when computer randomly selects scissor in the game.

3) Images scissor_p and  scissor_c are loaded on the canvas now using Tk.PhotoImage.

For Selection Image:

1) An variable named img_s is used to open the selection of hand images i.e. Combined image of Rock, Paper & Scissor, and resize it to (300,130).  

2) Image img_s is loaded on the canvas now using Tk.PhotoImage.

Part 2: Game Implementation

1) A game function is defined in which we have a list named select having values 1, 2, 3 representing rock, paper, and scissors respectively.

2) Here random.choice randomly selects options 1-3 for computer

3) Set image for Player on canvas

  • If Player selects 1 (Rock)  Show rock image on canvas using create_image.
  • If Player selects 2 (Paper) Show paper image on canvas using create_image.
  • If Player selects 3 (Scissor) Show scissor image on canvas using create_image.

4) Set image for Computer on canvas

  • If Computer selects 1 (Rock)  Show rock image on canvas using create_image.
  • If Computer selects 2 (Paper) Show paper image on canvas using create_image.
  • If Computer selects 3 (Scissor) Show scissor image on canvas using create_image.

5) Obtaining the result

  • If Player chooses Rock and computer chooses Rock OR If the player chooses Paper and the computer chooses Paper OR If the player chooses Scissor and the computer chooses Scissor. Result Shown-> Draw
  • If the Player chooses Rock and computer choose Scissor OR If the player chooses Paper and computer choose Rock OR If the player chooses Scissor and computer choose Paper.  Result Shown -> Player won
  • Else Result Shown-> Computer won

Note: This result is shown on canvas in form of text having dimensions (390,600), font=’Algerian’, tag=’result’.

  • Clear Button -> Deletes the present result and switches the figures at both sides to its default conditions.
  • Rock  Button -> Selects choice 1 in function game and Shows an Image of Hand showing Rock On Player side.
  • Paper Button -> Selects choice 2 in function game and Shows Image of Hand showing Paper On Player side
  • Scissor Button -> Selects choice 3 in function game and Shows an Image of Hand showing the Scissor On the Player side.

Images Used:

hand game in python assignment expert

default.jpg

hand game in python assignment expert

scissor.jpg

hand game in python assignment expert

Selection.jpg

Code Explanation:

  • The code starts by creating a window object called root.
  • The window has a title, which is “Rock Paper Scissor”.
  • The size of the window is set to 800×680 pixels.
  • Next, a canvas object is created.
  • The canvas has the same width and height as the window.
  • The grid command is used to create a grid on the canvas.
  • This will help us keep our drawings organized and easy to read.
  • The labels are then created using the text command.
  • Two labels are created – one for rock and one for paper.
  • These labels will be used in our game later on.
  • Finally, images are loaded into the canvas using the ImageTk library.
  • A random image is loaded for each player in our game (rock, paper, scissors).
  • The code creates a window and sets its title.
  • The window’s size is then set to 800×680 pixels.
  • Next, a canvas object is created and its grid attribute is set to row=0, column=0.
  • Finally, two labels are created and placed on the GUI window.
  • The code starts by creating three labels – Player, Computer, and Vs.
  • The first two labels are placed at the top-left corner of the window, while the third label is placed in the middle of the window.
  • Next, the code sets up some variables to store information about each label.
  • l1 and l2 are assigned a Label object with the name ‘Player’ and ‘Computer’, respectively.
  • l3 is assigned a Label object with the name ‘Vs’.
  • The next line creates an Image object named img_p and saves it to disk as a JPEG file.
  • The image size is set to 300×300 pixels.
  • Finally, img_p is initialized as an Image object.
  • The code creates three labels on the window, Player, Computer, and Vs.
  • The first label, l1, is placed at the top-left corner of the window and has a text of “Player” assigned to it.
  • The second label, l2, is placed in the middle of the window and has a text of “Computer” assigned to it.
  • The last label, l3, is placed at the bottom-right corner of the window and has a text of “Vs” assigned to it.
  • Next, the code opens an image named default.jpeg in Image object and sets its size to 300×300 pixels.
  • Finally, the code assigns this image as the default image for all three labels.
  • The code starts by loading the three images that will be used in the example.
  • The first image is a rock, the second is a paper, and the third is a selection image.
  • Next, the code flips each of these images so that they are displayed in reverse order.
  • This is done using the transpose() function.
  • The final step is to load each of these flipped images into an ImageTk PhotoImage object.
  • This allows us to display them onscreen together as one unit.
  • The code will first load the images “rock.jpeg”, “paper.jpeg”, and “scissor.jpeg” into the variables img_p, img_c, and scissor_p, respectively.
  • Next, the code will transpose each image’s left to right (LTR) direction so that they will be displayed on the canvas in their original orientation (RTL).
  • Finally, the code will create a new PhotoImage object for each image and assign it to the respective variables img_s and img_c.
  • The code first creates three images on the canvas.
  • The first image is at coordinates (0, 100), the second image is at coordinates (500, 100), and the third image is at coordinates (0, 400).
  • Next, the code defines a game function that will be used to control the player.
  • This game function takes one parameter – a player object – which represents a person in the game world.
  • The game function first checks to see if the player has moved within its bounds.
  • If not, it returns immediately.
  • Otherwise, it sets up two variables – x and y – to represent where on the screen the player currently is.
  • It then calls another function called draw() which will be used to draw all of the graphics in this game.
  • The draw() function first sets up an anchor point for each of its three images using create_anchor().
  • Next, it draws each of those images using create_image().
  • Finally, it assigns these values back to their respective variables so that they can be used by other parts of this program later on.
  • The code creates three images on the canvas, each at a specific coordinate.
  • The first image is at (0, 100), the second image is at (500, 100), and the third image is at (0, 400).
  • The game function will be called once for each of the three images.
  • In this function, we will ask the player to guess which of the three images they are looking at.
  • If they guess correctly, then the game is over and they win; if not, then we keep going.
  • The code starts by creating two variables, player and computer.
  • The player variable stores the value of 1, while the computer variable stores the value of 2.
  • Next, the code randomly selects one of the three options from the select list.
  • In this case, it randomly selects option 1.
  • The next line sets up an image for player on canvas using create_image().
  • The first argument is 0 (the x-coordinate), which specifies that the image should be placed at the bottom-left corner of the canvas.
  • The second argument is 100 (the y-coordinate), which specifies that the image should be centered in the canvas.
  • The third and fourth arguments are anchors (NW for north, NE for northeast, SW for southwest, and SE for southeast), which specify where on the canvas to place this image relative to other images on this canvas.
  • Finally, you provide a string representing your image filename.
  • Next, if player equals 1 (which means that we’re dealing with a rock object), then we use create_image() again but with a different set of arguments: anchor=WEST and image=rock_r.
  • This creates an image representing a rock object with its top facing westward.
  • If computer
  • The code will randomly select one of the three images (rock, paper, or scissor) to be displayed on the player’s canvas and also display the corresponding image for the computer.
  • The code begins by checking to see if the player is equal to or greater than the computer.
  • If so, then the code sets the result to “Draw”.
  • If not, then the code checks to see if the player is equal to or less than the computer.
  • If so, then the code sets the result to “You won”.
  • Finally, if neither of these conditions are met, then the code sets the result to “Computer won”.
  • The first condition checks whether player 1 is equal to 3 and computer 3.
  • The second condition checks whether player 2 is equal to 1 and computer 1.
  • The third condition checks whether player 3 is equal to 2 and computer 2.
  • If any of these comparisons are true, then that particular outcome will be set as the result.
  • The code compares the player’s number (1, 2, or 3) with the computer’s number (3, 2, or 1).
  • If the player equals the computer, then the result is set to “You won.”
  • If the player is different from the computer, then the code checks to see if the computer is winning.
  • If so, then the result is set to “Computer won.”
  • Otherwise, the code sets the result to “Draw.”
  • The code starts by creating a few variables.
  • The first is text, which will hold the message that is displayed on the screen.
  • Next, the code creates two buttons: rock_b and clear.
  • The rock_b button has a command attribute, which defines what action should be taken when it is clicked.
  • In this case, the command() function will be executed when the button is clicked.
  • This function takes one parameter—the number 1—and it will determine whether or not to play the game.
  • If you run this code now, you’ll see that clicking on the rock_b button results in a change in the message displayed onscreen (it now says “Result:- 0”).
  • The clear() function simply removes all of the content from the canvas object.
  • Finally, there are two images created using create_image().
  • The first image (img_p) will be placed at coordinates (0, 100), and its anchor point will be set to NW.
  • The second image (img_c) will be placed at coordinates (500, 100), and its anchor point will also be set to NW.
  • The code creates a button named rock_b on the root canvas.
  • The code defines the button as having the text Rock and a command that will run the game() function when clicked.
  • Next, the code creates two images on the canvas.
  • The first image is located at (0, 100) and has an anchor set to NW.
  • The second image is located at (500, 100) and also has an anchor set to NW.
  • Finally, the code defines a function named clear() that will remove all of the content from the canvas and replace it with default images.
  • The code in this example creates a three-button panel.
  • The first button is labeled “Paper,” and when it is clicked, the game() function is called.
  • This function takes two arguments: the number of turns that have passed since the last time the game was played, and the player’s current score.
  • The second button is labeled “Scissor.”
  • When it is clicked, the game() function is called again, but this time with an additional argument: the number of pieces left on the player’s side of the board.
  • If there are no more pieces left on that side of the board, then game over!
  • The third button is labeled “Clear.”
  • When it is clicked, all buttons and text in the panel are cleared (including any text that has been entered into those buttons by users).
  • The code creates a button named ‘paper_b’ and a button named ‘scissor_b’.
  • The first button will be activated when the player clicks on it, while the second button will be activated when the player presses down on it.
  • Finally, the last button is used to clear the screen.
  • When creating these buttons, you should keep in mind that they should be placed at different locations on the screen so that they are easy to access.
  • For example, paper_b should be placed at (x=128, y=487), while scissor_b should be placed at (x=220, y=487).

Please Login to comment...

  • ProGeek 2021
  • Python Tkinter-projects
  • Python-projects
  • Python-tkinter
  • ankit_kumar_

Improve your Coding Skills with Practice

 alt=

IMAGES

  1. Hand Gesture Controlling Game In python using OpenCV Archives

    hand game in python assignment expert

  2. Python Game Project: Play Dino Game Using Hand Gesture

    hand game in python assignment expert

  3. How to Make A Simple Game in Python (For Beginners)

    hand game in python assignment expert

  4. #12

    hand game in python assignment expert

  5. 15 Best Python Game Project Ideas for Easy Learning

    hand game in python assignment expert

  6. Hands on Computer Games using Python Step by Step

    hand game in python assignment expert

VIDEO

  1. 💥Operators in Python

  2. Python Beginner's Course Lesson 4

  3. Python Beginner's Course Lesson 4

  4. Python, Colt Hand Engraved

  5. Assignment

  6. VaultofCodes Internship

COMMENTS

  1. Answer in Python for umesh #234368

    Question #234368 Hand game Abhinav and Anjali are playing Rock-Paper-Scissors game. Rock-Paper-Scissors is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper" and "scissors".

  2. Answer in Python for hemanth #164730

    Question #164730 Abhinav and Anjali are playing Rock-Paper-Scissors game. Rock-Paper-Scissors is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper" and "scissors".

  3. Answer in Python for prathyusha #164741

    Rock-Paper-Scissors is a hand game usually 3. Describe the difference between a chained conditional and a nested conditional. Give your own exampl 4. Given a string of length N, made up of only uppercase characters 'R' and 'G', wh 5.

  4. Rock, Paper, Scissor game

    Practice In this article, we will see how we can create a rock paper and scissor game using Tkinter. Rock paper scissor is a hand game usually played between two people, in which each player simultaneously forms one of the three shapes with an outstretched hand. These shapes are “rock”, “paper”, and “scissors”. Game Winner Conditions