Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Rock Paper Scissors Game, I need help.
#1
Hello,

I recently started learning python and I'm having lots of fun!
I made a very very simple, beginner game of Rock Paper Scissors, but I've hit a roadblock.

I tried to implement a sort of "error-detection" system where if either player types anything other than "rock", "paper", "scissors", the result will print "Please type correct choices!"
However, no matter what I type, I end up getting "Please type correct choices!" message.

Can you guys help me where I messed up my code? I'm assuming that I messed up line 8...

I appreciate your help!

print("Welcome to the great game of Rock Paper Scissors!")
print("Here is the rule.\nPlayer 1 enters his/her choice.\nPlayer 2 enters his/her choice.\n")

p1 = input("Player 1, please enter your choice: ").lower()
p2 = input("Player 2, please enter your choice: ").lower()


if p1 == ("rock" or "paper" or "scissors") and p2 == ("rock" or "paper" or "scissors"):
	if p1 == p2:
		print("It's a tie!")
	elif p1 == "rock":
		if p2 == "paper":
			print("Player 2 wins!")
		else:
			print("Player 1 wins!")
	elif p1 == "paper":
		if p2 =="scissors":
			print("Player 2 wins!")
		else:
			print("Player 1 wins!")
	elif p1 == "scissors":
		if p2 == "rock":
			print("Player 2 wins!")
		else:
			print("Player 1 wins!")	
else:
	print("Please type correct choices!")
Quote
#2
You are using the or operator wrong. You need to have an expression on each side of the or (see here for details). What you want is:

valid = ('rock', 'paper', 'scissors')
if p1 in valid and p2 in valid:
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
(Feb-14-2019, 04:04 AM)ichabod801 Wrote: You are using the or operator wrong. You need to have an expression on each side of the or (see here for details). What you want is:

valid = ('rock', 'paper', 'scissors')
if p1 in valid and p2 in valid:

Thank you so much for your help! I now know what I did wrong. Thank you again.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  rock paper scissors game abscorpy 8 719 Feb-14-2019, 07:20 PM
Last Post: abscorpy
  [PyGame] Game Logic problem with a "The Game of Life" Replication Coda 2 629 Dec-24-2018, 09:26 AM
Last Post: Coda
  [PyGame] Rock,paper,scissors Game(beginner) r0d 10 3,242 Jan-16-2018, 08:01 PM
Last Post: r0d

Forum Jump:


Users browsing this thread: 1 Guest(s)