Python Forum
Basic Rock, Paper, Scissors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Rock, Paper, Scissors
#1
Hello! Big Grin

Today, I created my first running version of really anything I've done with Python. It is a Rock, Paper, Scissors game. After creating a calculator which is usually the first thing you make when starting a new language after 'Hello World', using my knowledge from that I decided to create the Rock, Paper, Scissors game by myself. Angel

I included the sleep function and also some 'confirm selection' questions to add to the user's experience.

CODE

import time import random def main(): """Body of program. Playing 'Rock, Paper, Scissors' against a bot""" # Introduction print("") print("Rock, Paper, Scissors") print("-------------------------") completegame = False while not completegame: print("") time.sleep(1) """RUNS USER'S SELECTION PHASE""" user_selection = False while not user_selection: """Runs the user's turn""" try: print("Please choose a selection from the following moves...") print("") time.sleep(2) print("1) ROCK") time.sleep(0.5) print("2) PAPER") time.sleep(0.5) print("3) SCISSORS") print("") time.sleep(0.7) usermove = int(input("Chosen move (enter a number):")) if usermove == 1: time.sleep(0.5) print("You chose to use ROCK. Is this correct?") time.sleep(2) confirmselection = input("Type 'y' for YES or any other input for NO") if confirmselection == 'y': usermove = "ROCK" user_selection = True else: print("") time.sleep(1) print("You chose to change your move...") print("") time.sleep(2) elif usermove == 2: time.sleep(0.5) print("You chose to use PAPER. Is this correct?") time.sleep(2) confirmselection = input("Type 'y' for YES or any other input for NO") if confirmselection == 'y': usermove = "PAPER" user_selection = True else: print("") time.sleep(1) print("You chose to change your move...") print("") time.sleep(2) elif usermove == 3: time.sleep(0.5) print("You chose to use SCISSORS. Is this correct?") time.sleep(2) confirmselection = input("Type 'y' for YES or any other input for NO") if confirmselection == 'y': usermove = "SCISSORS" user_selection = True else: print("") time.sleep(1) print("You chose to change your move...") print("") time.sleep(2) except: print("Invalid Input") """RUNS COMPUTER'S SELECTION PHASE""" botmove = int(random.randint(1, 3)) # Declares the computer's move if botmove == 1: botmove = "ROCK" elif botmove == 2: botmove = "PAPER" elif botmove == 3: botmove = "SCISSORS" """COMPARES CHOICES AND DECLARES A WINNER""" print("") print("Declaring winner...") time.sleep(2) print("") print("You chose", usermove) time.sleep(2) print("The computer chose", botmove) time.sleep(1) if (usermove == "ROCK" and botmove == "ROCK") or \ (usermove == "PAPER" and botmove == "PAPER") or \ (usermove == "SCISSORS" and botmove == "SCISSORS"): print("") print("Both participants chose the same!") time.sleep(2) print("") print("Restarting game...") print("") time.sleep(3.5) print("-----------------------------------------------") print("") elif (usermove == "ROCK" and botmove == "SCISSORS") or \ (usermove == "PAPER" and botmove == "ROCK") or \ (usermove == "SCISSORS" and botmove == "PAPER"): print("") print("You WIN!!!!") completegame = True elif (botmove == "ROCK" and usermove == "SCISSORS") or \ (botmove == "PAPER" and usermove == "ROCK") or \ (botmove == "SCISSORS" and usermove == "PAPER"): print("") print("The computer won!") time.sleep(2) print("") print("Restarting game...") print("") time.sleep(3.5) print("-----------------------------------------------") print("") main()
- CinnamonBeard
Reply
#2
Please note, your indentation is incorrect. When pasting between tags, use the key combination "Ctrl + Shift + V".
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Another Rock, Paper, Scissors Yoriz 4 4,754 Jun-30-2020, 07:56 PM
Last Post: Yoriz
  The tkinter version of Rock Paper Scissors menator01 3 4,804 Jun-28-2020, 07:15 AM
Last Post: ndc85430
  My version of Rock Paper Scissors menator01 12 9,443 Jun-27-2020, 10:25 PM
Last Post: menator01
  PyQt5 Version of Rock, Paper, & Scissors menator01 8 5,896 Jun-06-2020, 12:15 PM
Last Post: pyzyx3qwerty
  Rock, Paper, Scissors foksikrasa 11 7,515 May-28-2020, 05:58 PM
Last Post: BitPythoner
  Rock Paper Scissor GAME inamullah9 3 5,005 Aug-11-2019, 12:17 PM
Last Post: ichabod801
  A CLI based Rock,Paper or Scissor game. Ablazesphere 7 6,849 Oct-28-2018, 07:25 AM
Last Post: Ablazesphere
  A basic Rock-paper-scissors game by me... Unlimiter 0 3,282 Dec-25-2017, 03:41 PM
Last Post: Unlimiter

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.