Python Forum
A basic Rock-paper-scissors game by me...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A basic Rock-paper-scissors game by me...
#1
"""A basic program/game that simulates Rock-Paper-Scissors with text"""

# I need random library to randomise the bot's actions.
import random

# Title & help:
print("Rock-papaer-scissors Game - By Hicham Labidi.\n- 'r' for rock.\n- 'p' for paper.\n- 'sc' for scissors.\n")

# sets the variable wich stores whose turn it is, and the two boolean variables explained below.
turn = 0
UserAgain = False
BotAgain = False
		
# defines the function that runs the game's starting events:
def start():
	isUserAgain = UserAgain
	isBotAgain = BotAgain
	# randomises the turn variable, so we have a random turn every time:
	turn = random.randint(1, 2)	
	''' what to do if someone's turn is the current one: '''
	if turn == 1:
		''' if it's the user's turn: '''
		print("It's your turn!")
		# lets the user choose:
		user_choice = input("Choose either 'r', 'p' or 'sc': ")
		# for user: r - rock, p - paper, sc - scissors.
		bot_choice = random.randint(1, 3)
		# for bot: 1 - rock, 2 - paper, 3 - scissors.
		# print what bot choosed:
		if bot_choice == 1:
			print("Bot choosed 'rock'.")
		elif bot_choice == 2:
			print("Bot choosed 'paper'.")
		else:
			print("Bot choosed 'scissors'.")
		
		check(user_choice, bot_choice)
		
	else:
		''' if it's the bot's turn: '''
		print("It's bot's turn!")
		bot_choice = random.randint(1, 3)
		# for bot: 1 - rock, 2 - paper, 3 - scissors.
		# prints that the bot choosed something:
		print("Bot choosed something.")
		# lets the user choose:
		user_choice = input("Choose either 'r', 'p' or 'sc': ")
		# for user: r - rock, p - paper, sc - scissors.
		
		# prints what bot choosed:
		if bot_choice == 1:
			print("Bot choosed 'rock'.")
		elif bot_choice == 2:
			print("Bot choosed 'paper'.")
		else:
			print("Bot choosed 'scissors'.")
		
		check(bot=bot_choice, user=user_choice)
			
# defines the function that checks who's the winner:
def check(user, bot):
	if user == 'r' and bot == 3 or user == 'sc' and bot == 2 or user == 'p' and bot == 1:
		print("You win!\n")
		
	elif user == 'r' and bot == 2 or user == 'sc' and bot == 1 or user == 'p' and bot == 3:
		print("You lose!\n")
		
	elif user == 'r' and bot == 1 or user == 'p' and bot == 2 or user == 'sc' and bot == 3:
		print("Draw!\n")
		
	start()

start()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Another Rock, Paper, Scissors Yoriz 4 3,131 Jun-30-2020, 07:56 PM
Last Post: Yoriz
  The tkinter version of Rock Paper Scissors menator01 3 3,149 Jun-28-2020, 07:15 AM
Last Post: ndc85430
  My version of Rock Paper Scissors menator01 12 6,036 Jun-27-2020, 10:25 PM
Last Post: menator01
  PyQt5 Version of Rock, Paper, & Scissors menator01 8 3,622 Jun-06-2020, 12:15 PM
Last Post: pyzyx3qwerty
  Rock, Paper, Scissors foksikrasa 11 4,256 May-28-2020, 05:58 PM
Last Post: BitPythoner
  Rock Paper Scissor GAME inamullah9 3 3,235 Aug-11-2019, 12:17 PM
Last Post: ichabod801
  A CLI based Rock,Paper or Scissor game. Ablazesphere 7 4,431 Oct-28-2018, 07:25 AM
Last Post: Ablazesphere
  Basic Rock, Paper, Scissors CinnamonBeard 1 3,529 Dec-19-2017, 02:32 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020