Sep-30-2017, 01:42 AM
(This post was last modified: Sep-30-2017, 02:25 AM by samiraheen.)
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^
>>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^