GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

Rock Paper Scissors Game in Python (Using Random Module)

Gk Scientist December 3, 2022 No Comments
Tweet WhatsApp Telegram

Rock Paper Scissors Game in Python:

We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.

Rock Paper Scissors Game Rules:

  • Rock smashes Scissors- Rock wins.
  • Paper covers Rock- Paper wins.
  • Scissors cuts Paper- Scissors wins.

Code Unit:

Rock Paper Scissors Game in Python Code 1 - Rock Paper Scissors Game in Python (Using Random Module)
Rock Paper Scissors Game in Python Code 2 - Rock Paper Scissors Game in Python (Using Random Module)
Rock Paper Scissors Game in Python Code 3 - Rock Paper Scissors Game in Python (Using Random Module)

Output:

Rock Paper Scissors Game in Python Output1 - Rock Paper Scissors Game in Python (Using Random Module)
Rock Paper Scissors Game in Python Output2 - Rock Paper Scissors Game in Python (Using Random Module)

Rock Paper Scissors Game in Python Source Code: Do proper Code Indentation otherwise, the Source Code does not work and gives an error.

import random

class color:
 Bold = '\033[1m'
 RED = '\033[91m'
 DARKCYAN = '\033[36m'
 END = '\033[0m'

x=["rock","paper","scissors"]

while True:
   computer_count=0
   user_count=0
   user_action=int(input('''
     Game Start...
     Press 1 to Play
     Press 2 to Exit
      '''))

   if user_action==1:
      for a in range(1,6):
          user_input=int(input('''
            1 Rock
            2 Paper
            3 Scissors
            '''))

          if user_input == 1:
              user_choice ="rock"
          elif user_input == 2:
              user_choice ="paper"
          elif user_input == 3:
              user_choice ="scissors"
          computer_choice = random.choice(x)

          if computer_choice == user_choice:
              print(color.RED +"Computer Value", computer_choice + color.END)
              print(color.RED +"User Value", user_choice + color.END)
              print(color.DARKCYAN +"Game Draw"+color.END)
              user_count = user_count + 1
              computer_count = computer_count + 1
          elif(user_choice =="rock" and computer_choice == "scissors") or (user_choice =="paper"
          and computer_choice == "rock") or (user_choice =="scissors" and computer_choice == "paper"):
              print(color.RED +"Computer Value", computer_choice + color.END)
              print(color.RED +"User Value", user_choice + color.END)
              print(color.DARKCYAN +"You Win"+color.END)
              user_count = user_count + 1
          else:
              print(color.RED +"Computer Value", computer_choice + color.END)
              print(color.RED +"User Value", user_choice + color.END)
              print(color.DARKCYAN +"Computer Win"+color.END)
              computer_count = computer_count + 1

      if user_count == computer_count:
          print("-----------------------------------------")
          print(color.Bold + color.DARKCYAN + "Game Draw.....Play Again"+color.END)
          print(color.RED +"user Score", user_count, color.END)
          print(color.RED +"Computer Score", computer_count, color.END)
      elif user_count > computer_count:
          print("-----------------------------------------")
          print(color.Bold + color.DARKCYAN + "Congratulations, You Win the Game......."+color.END)
          print(color.RED +"user Score", user_count, color.END)
          print(color.RED +"Computer Score", computer_count, color.END)
      else:
          print("-----------------------------------------")
          print(color.Bold + color.DARKCYAN + "Sorry, Computer Win the Game......."+ color.END)
          print(color.RED +"user Score", user_count, color.END)
          print(color.RED +"Computer Score", computer_count, color.END)

   else:
     break

Spooling and Virtual Devices
Information Security in E-Commerce
Client-Server Architecture
Python String Function
String Iteration in Python
String Indexing and String Slicing in Python
Python (programming language)– Wikipedia
Prev Article
Next Article

Related Articles

Java Random Class
Java Random Class: We can use the Eclipse IDE for …
Gk Scientist January 1, 2023 Computer

Java Random Class

FTP (File Transfer Protocol)
FTP: FTP is an acronym for File Transfer Protocol. FTP …
Gk Scientist September 17, 2022 Computer

FTP (File Transfer Protocol)

Python MySQL Inner Join
Python MySQL Inner Join: (1) The MySQL Inner Join clause …
Gk Scientist December 14, 2022 Computer

Python MySQL Inner Join

Internet and Its Uses
Internet: Nowadays, the Internet has become an integral part of …
Gk Scientist September 14, 2022 Computer

Internet and Its Uses

Python Function Overloading and Overriding
Python Function Overloading and Overriding: We can use the PyCharm …
Gk Scientist December 6, 2022 Computer

Python Function Overloading and Overriding

Python Tic Tac Toe Game Project
Python Tic Tac Toe Game Project: We can use the …
Gk Scientist December 22, 2022 Computer

Python Tic Tac Toe Game Project

Procedure-Oriented Programming
Procedure-Oriented Programming: Procedure-Oriented Programming is the traditional way of programming, …
Gk Scientist August 14, 2022 Computer

Procedure-Oriented Programming

Create Database in MySQL
Create Database in MySQL: (1) In order to create a …
Gk Scientist November 10, 2022 Computer

Create Database in MySQL

Leave a Reply Cancel Reply

Search

  • Popular
  • Recent




GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (33) Biology Questions (88) Chemistry (57) Computer (215) Current Affairs (4) Current Content (0) Economy (15) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (114) Physics (89) Political Science (132) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
 

Loading Comments...