Python Forum
Rock, Paper, Scissors Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock, Paper, Scissors Game
#2
Try this to see if it helps,

items=['paper','scissors','rock']# items list
i=True
while i==True:
	#read strings , convert lower
	p_1=input("\nenter player 1 choice: ").lower()
	p_2=input("enter player 2 choice: ").lower()
	if (p_1 != p_2) and (p_1 in items) and (p_2 in items):# verify not same and given input are in list-items
		if (p_1=="rock" and p_2=="scissors") or (p_1=="paper" and p_2=="rock") or (p_1=="scissors" and p_2=="paper"):#player 1 win criteria
			print(f"{p_1} beats {p_2} , player 1 win!")
		else:
			print(f"{p_2} beats {p_1} , player 2 win!")
		#play again? yes/not
		playagain=input("play again: (yes/no) : " ).lower()
		if playagain == "yes":
			i=True
		else:
			i=False # stop while loop
	else:
		print(f"bad input/same words, {p_1,p_2} retrying game ")
		pass 
Output:
python test1.py enter player 1 choice: ROck enter player 2 choice: PAPER paper beats rock , player 2 win! play again: (yes/no) : yes enter player 1 choice: rock enter player 2 choice: scissors rock beats scissors , player 1 win! play again: (yes/no) : yes enter player 1 choice: paper enter player 2 choice: SCISSORS scissors beats paper , player 2 win! play again: (yes/no) : yes enter player 1 choice: paper enter player 2 choice: rock paper beats rock , player 1 win! play again: (yes/no) : yes enter player 1 choice: scissors enter player 2 choice: paper scissors beats paper , player 1 win! play again: (yes/no) : yes enter player 1 choice: scissors enter player 2 choice: rock rock beats scissors , player 2 win! play again: (yes/no) : yes enter player 1 choice: rock enter player 2 choice: ROCK bad input/same words, ('rock', 'rock') retrying game enter player 1 choice: rrr enter player 2 choice: ttt bad input/same words, ('rrr', 'ttt') retrying game enter player 1 choice: rock enter player 2 choice: paper paper beats rock , player 2 win! play again: (yes/no) : no
Few observations on your code,
#lower() to be applied for the input taken variables, not on right hand side of comparing text.
(eg: player_1.lower() == 'paper':)

#None, because, assume rock, paper given, it first match main elif block, then it only have if block, it fail compare to scissors and thus looks for else or elif inside the main elif , found nothing and closing main elif and returning None with statemtnt print(play(p_1, p_2)) as none of if/elif/else got match return though elif block sucessful with p_!, but exited as no catch of p_2 string, i guess.

#tryagain code, you took input yes but no block/function defined to repeat taking inputs for re-run.

#elif conditions were looking little complex, may be you can try like,

elif player_1.lower() == 'rock':
		if player_2.lower() == 'scissors':
			return "Rock hits scissors. Player 1 win!"
		elif player_2.lower() == 'paper':
			return "Paper covers rock. Player 2 wins!"
			
elif player_1.lower() == 'paper':
		if player_2.lower() == 'scissors':
			return "Scissors cut paper. Player 2 wins"
		elif player_2.lower() == 'rock':
			return "Paper covers rock. Player 1 wins!"
			
elif player_1.lower() == 'scissors':
		if player_2.lower() == 'rock':
			return "Rock hits scissors. Player 2 wins!"
		elif player_2.lower() == 'paper':
			return "Scissors cut paper. Player 1 wins!"
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply


Messages In This Thread
Rock, Paper, Scissors Game - by kramon19 - Jan-10-2020, 03:10 AM
RE: Rock, Paper, Scissors Game - by sandeep_ganga - Jan-10-2020, 07:14 AM
RE: Rock, Paper, Scissors Game - by perfringo - Jan-10-2020, 08:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,934 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,260 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,881 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,229 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 5,079 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  Rock paper scissors game samiraheen 3 6,387 Oct-03-2017, 07:07 PM
Last Post: buran
  The Python Book altered rock paper scissors Python_Noob 0 2,929 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  HELP---problems with rock paper scissors games kalt91 2 4,151 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock, Paper, Scissors game help.. hentera 3 5,083 May-19-2017, 10:56 PM
Last Post: ichabod801
  Rock Paper Scissors game codeobri 3 13,447 Apr-28-2017, 01:02 AM
Last Post: codeobri

Forum Jump:

User Panel Messages

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