Python Forum
Rock paper scissors game
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock paper scissors game
#1
I want to write a function that determines the result of a rock, paper, scissors game given choices of player 1 and player 2. My function is rps_winner() and I want it to prompt the user for choice of player 1 and then choice of player 2, and then display the result for player 1. The user will only enter words: rock, paper or scissors in lower case. If both players make the same choice, we have a draw. I have started out my code like this, but I am unsure how to make it run like this for example.

>>rps_winner()
What choice did player 1 make?
Type one of the following options: rock, paper, scissors: rock
What choice did player 2 make?
Type one of the following options: rock, paper, scissors: paper
Player 1 wins. That is False
It is a tie. That is not True

My code at the bottom

>>def rps_winner():
print("What choice did player 1 make?")
p1 = input("Type one of the following options: rock, paper, scissors:")
print("What choice did player 2 make?")
p2 = input("Type one of the following options: rock, paper, scissors:")
p1_wins = (p1 == 'paper' and p2 == 'rock') or (p1 == 'scissors' and p2 == 'paper') or (p1 == 'rock' and p2 == 'scissors')
p2_wins = (p2 == 'paper' and p1 == 'rock') or (p2 == 'scissors' and p1 == 'paper') or (p2 == 'rock' and p1 == 'scissors')
It is a tie = (p1 == p2)
return print('Player 1 wins. That is ' + str(p1_wins

Any help would be appreciated

def rps_winner():
print("What choice did player 1 make?")
p1 = input("Type one of the following options: rock, paper, scissors:")
print("What choice did player 2 make?")
p2 = input("Type one of the following options: rock, paper, scissors:")
p1_wins = (p1 == 'paper' and p2 == 'rock') or (p1 == 'scissors' and p2 == 'paper') or (p1 == 'rock' and p2 == 'scissors')
p2_wins = (p2 == 'paper' and p1 == 'rock') or (p2 == 'scissors' and p1 == 'paper') or (p2 == 'rock' and p1 == 'scissors')
It is a tie = (p1 == p2)
return print('Player 1 wins. That is ' + str(p1_wins

there u go^
Reply
#2
Does it work?  Do you get any errors? 
Or is the output you currently get different from what you expected?  And, if that's the case, what did you get, and what did you expect?
Reply
#3
Okay, you are in the right ballpark at least. (I am referring to 2.7)

Some hints.

use raw_input instead of input
so something like this.


print "What choice did player 1 make?"
print "Type one of the following options: rock, paper scissors:"
p1 = raw_input()

make you return value a string, and set it to draw. then use if statements to change it if player one or player 2 won. if both if statements are not valid, your default (draw) wins.

Return that string.

call the function and print the result. I was able to get it working in about 2 minutes, would post the code but I am not sure if the teacher wants you to figure it out or not.
Reply
#4
(Oct-03-2017, 06:50 PM)zedwardson Wrote: Okay, you are in the right ballpark at least. (I am referring to 2.7) Some hints. use raw_input instead of input so something like this.


OP is clearly using python 3. Don't advise him to go back to python2. If not for other reason - this will add extra confusion
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,925 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,224 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  Rock, Paper, Scissors Game kramon19 2 5,362 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,856 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,214 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 5,046 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  The Python Book altered rock paper scissors Python_Noob 0 2,922 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  HELP---problems with rock paper scissors games kalt91 2 4,131 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock, Paper, Scissors game help.. hentera 3 5,064 May-19-2017, 10:56 PM
Last Post: ichabod801
  Rock Paper Scissors game codeobri 3 13,419 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