Python Forum
[PyGame] Rock,paper,scissors Game(beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Rock,paper,scissors Game(beginner)
#1
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()
Reply
#2
What error do you get?
And please try re-posting your code in code tags, so it can actually be read.
Reply
#3
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()
Reply
#4
My mistake.  Please share the full error.  It should include snippets of the code, and be something like 4 lines long.
Reply
#5
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
Reply
#6
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()
Recommended Tutorials:
Reply
#7
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?
Reply
#8
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.
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
#9
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#10
Thanks everyone for their input, much appreciated ! Awesome Community
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock/Paper/Scissors Game 1 abscorpy 6 3,727 Dec-01-2020, 10:08 PM
Last Post: metulburr
  randomization code in rock, paper, scissors cel 4 2,629 May-28-2020, 08:48 PM
Last Post: cel
  rock paper scissors game abscorpy 8 4,409 Feb-14-2019, 07:20 PM
Last Post: abscorpy
  Rock Paper Scissors Game, I need help. extraguac 2 2,484 Feb-14-2019, 04:34 AM
Last Post: extraguac

Forum Jump:

User Panel Messages

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