Python Forum
[PyGame] Rock,paper,scissors Game(beginner) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] Rock,paper,scissors Game(beginner) (/thread-5328.html)

Pages: 1 2


Rock,paper,scissors Game(beginner) - r0d - Sep-28-2017

Can someone explain to me whats wrong with my code, im new to python and i figure to practice a little, to create a rock paper scissors game



def game():
print "Welcome to Rock, Paper, Sciscors Game !"

player1=raw_input("player1 enter your name: ")
player2=raw_input("player2 enter your name: ")

choose=raw_input("%s chooses Rock,Paper,or Sciscors") %(player1)
choose1=raw_input("%s chooses Rock, Paper, or Sciscors") %(player2)

if player1=="Rock" or player2=="Sciscors":
print "%s won" %(player1)
elif player2 =="Sciscors" or player1 =="Paper":
print "%s won" %(player2)
elif player1 == "Paper" or player2 == "Rock":
print "%s won" %s(player1)
elif player2 == "Rock" or player1 =="Paper":
print "%s won" %s(player1)
elif player1 == "Paper" or player2 =="Sciscors":
print "%s won" %s(player2)
else:
print "you didnt choose Rock,Paper, or Sciscors, try again"
game()

game()



RE: Rock,paper,scissors Game(beginner) - nilamo - Sep-28-2017

What error do you get?
And please try re-posting your code in code tags, so it can actually be read.


RE: Rock,paper,scissors Game(beginner) - r0d - Sep-28-2017

Sorry about that, i get a syntax error on line 11

def game():
	print "Welcome to Rock, Paper, Sciscors Game !"

	player1=raw_input("player1 enter your name: ")
	player2=raw_input("player2 enter your name: ")

	choose=raw_input("%s chooses Rock,Paper,or Sciscors") %(player1)
	choose1=raw_input("%s chooses Rock, Paper, or Sciscors") %(player2)

	if player1=="Rock" or player2=="Sciscors":
		print "%s won" %(player1)
		elif player2 =="Sciscors" or player1 =="Paper":
			print "%s won" %(player2)
			elif player1 == "Paper" or player2 == "Rock":
				print "%s won" %s(player1)
			elif player2 == "Rock" or player1 =="Paper":
				print "%s won" %s(player1)
			elif player1 == "Paper" or player2 =="Sciscors":
				print "%s won" %s(player2)
				else:
					print "you didnt choose Rock,Paper, or Sciscors, try again"
					game()
		
game()



RE: Rock,paper,scissors Game(beginner) - nilamo - Sep-28-2017

My mistake.  Please share the full error.  It should include snippets of the code, and be something like 4 lines long.


RE: Rock,paper,scissors Game(beginner) - r0d - Sep-28-2017

The Error


Error:
Traceback (most recent call last): File "/run_dir/remotedebugger.py", line 140, in run bdb.Bdb.run(self, cmd, globals=globals, locals=locals) File "/usr/local/lib/python3.6/bdb.py", line 428, in run cmd = compile(cmd, "<string>", "exec") File "<string>", line 11 print "%s won" %(player1) ^ SyntaxError: invalid syntax



RE: Rock,paper,scissors Game(beginner) - metulburr - Sep-28-2017

Looks like you are using python 3.x .Change that line to
print('{} won'.format(player1))
change all the print statements to print functions and change all the raw_input() to input()


RE: Rock,paper,scissors Game(beginner) - nilamo - Sep-28-2017

I don't know, the error would have been on line 2 if that was the case.  OP: what's the output of python -V?


RE: Rock,paper,scissors Game(beginner) - sparkz_alot - Sep-29-2017

You have several problems. Remove the 's' after the percent sign preceding 'playerx' on lines 15, 17 and 19. You do not need the extra parenthesis around 'playerx' in lines 7, 8, 11, 13 15, 17, and 19. Finally, you have two variables: 'choose' and  'choose1', which you do not use. I believe you mean to use those in your 'if/elif/else' conditional, rather than players name.

There may be more, as was pointed out, depending on the Python version you are running.


RE: Rock,paper,scissors Game(beginner) - ichabod801 - Sep-29-2017

The indentation you posted is off. Make sure all the elifs and the else line up with the original if. Also, your parentheses are wrong for the raw_input. The % player1 should be inside the parentheses for the raw_input.

Note that even with the variable problem that sparkz pointed out, you are not checking all the possibilities. There are six ways for a win to happen, and you only test for five. Also, you are assuming that if there's no win, someone entered and invalid play. You need to check to see if there was a tie before you do that.


RE: Rock,paper,scissors Game(beginner) - r0d - Sep-29-2017

Thanks everyone for their input, much appreciated ! Awesome Community