Day 014 - Project 14 : 2 player rock paper scissors

If you have any questions, comments or issues with this project please post them here!

The challenge says to make it so that the players can’t see each other’s answers, I am a bit confused about how to do this, can someone help by pointing me in the right direction?

1 Like

@StavrosCotsorad Welcome to the community.

As it says on page one you have to add the following code to the top of the file
from getpass import getpass as input
This will mean that inputs are hidden!

Screenshot 2023-01-05 6.26.59 PM

2 Likes

:rock: :page_facing_up::scissors: My very first multiplayer game !!!

https://replit.com/@JackAdem/Day-014-Project-14-2-player-rock-paper-scissors?v=1

Day 14 of #Replit100DaysOfCode #100DaysOfCode.

3 Likes

Ok so it works, technically. However, i’m not sure how to assign the letters to words that they represent, for example p to paper and so on…i’ve tried to make it as simple and lean as possible, and i think that is where i’m going wrong? Thanks for any help

from getpass import getpass as input

print("Hidden Rock, paper, scissors!")

user_choice1 = input("Player 1 Rock, Paper, or Scissors? ")
user_choice1 = user_choice1
user_choice2 = input("Player 2 Rock, Paper, or Scissors? ")
user_choice2 = user_choice2
print()




if user_choice1 == user_choice2:
    winner = 'Tie'
elif user_choice1 == 'p' and user_choice2 == 'r':
    winner = 'Player 1'
elif user_choice1 == 'r' and user_choice2 == 's':
    winner = 'Player 1'
elif user_choice1 == 's' and user_choice2== 'p':
    winner = 'Player 1'
else:
    winner = 'Player 2'

if winner == 'Tie':
    print("We both chose", user_choice1, "play again! ")

else:
    print(winner, 'won.  Player 1 chose ', user_choice1 + '.', ' Player 2 chose', user_choice2 + '.') 
    

1 Like

IIRC David’s solution was very similar to yours, not sure what you mean by assigning letters to the words they represent.

So I think your solution is fine.

2 Likes

I’m not sure who that is (David), but what I meant was having the letters r,p,s correspond to the actual words they represent

1 Like

Using a dictionary:

from getpass import getpass as input

print("Hidden Rock, paper, scissors!")

user_choice1 = input("Player 1 Rock, Paper, or Scissors? ")
user_choice1 = user_choice1
user_choice2 = input("Player 2 Rock, Paper, or Scissors? ")
user_choice2 = user_choice2
print()


actual_names = {"r": "rock", "p": "paper", "s": "scissors"}

if user_choice1 == user_choice2:
    winner = 'Tie'
elif user_choice1 == 'p' and user_choice2 == 'r':
    winner = 'Player 1'
elif user_choice1 == 'r' and user_choice2 == 's':
    winner = 'Player 1'
elif user_choice1 == 's' and user_choice2== 'p':
    winner = 'Player 1'
else:
    winner = 'Player 2'

if winner == 'Tie':
    print("We both chose", user_choice1, "play again! ")

else:
    print(winner, 'won.  Player 1 chose ', actual_names[user_choice1] + '.', ' Player 2 chose', actual_names[user_choice2] + '.') 

Note: this is untested

2 Likes

David is the one who taught the lessons in the videos :laughing:

1 Like

exactly what i needed, awesome thanks ! :slightly_smiling_face:

1 Like

oh right, i forgot his name lol

I got most of the code for this lesson from my RPS game i did about a month ago against the computer (which was actually an exercise form a python book i read before starting replit)

mport random

winner = ''

random_choice = random.randint(0,2)

if random_choice == 0:
    computer_choice = 'rock'
elif random_choice == 1:
    computer_choice = 'paper'
else:
    computer_choice = 'scissors'
    
user_choice = ''
while (user_choice != 'rock' and
       user_choice != 'paper' and
       user_choice != 'scissors'):
    user_choice = input('rock, paper or scissors? ')

if computer_choice == user_choice:
    winner = 'Tie'
elif computer_choice == 'paper' and user_choice == 'rock':
    winner = 'Computer'
elif computer_choice == 'rock' and user_choice == 'scissors':
    winner = 'Computer'
elif computer_choice == 'scissors' and user_choice == 'paper':
    winner = 'Computer'
else:
    winner = 'User'

if winner == 'Tie':
    print("We both chose", user_choice + ", play again! ")

else:
    print(winner, 'won.  The user chose', user_choice + '.', ' the computer chose', computer_choice + '.') 
    
1 Like

Tip: use random.choice(list) instead of random.randint, it saves you from if statements

1 Like

Question:
Hello Everyone :stuck_out_tongue:
I have been here before and got some great answers quickly. I was wondering why my code isn’t printing any of my code in python. I am still pretty new to this and first time trying to solve problems using code. I enjoy it. When it works. This time I can’t find out why any of the code isn’t printing after it gets a response from both users.

Repl link:
https://replit.com/@DigitalNomadjoe/day-14100-daysrockpaperscissors

from getpass import getpass as input

print("👏 ROCK ⛰️, PAPER 🧻, SCISSORCS ✂️ 👏 \n\n")

print("Welcome to the basic rock paper scissors game. Will add to it more when I learn more in the future :P \n\n")

playerOne = input("Hello, \n\nWhat is your name Player One? \n")
print()
playerTwo = input("Hello, \n\nWhat is your name Player 2? \n")

getAnswer = input(print(f"Welcome \n\n{playerOne} and {playerTwo} \n\nReady to play ⛰️ Rock(r), 🧻 Paper(p), ✂️ Scissors(s) \ny = Yes, n = No 😅 \n"))


if getAnswer == "y" or "yes":
  print("Okay Lets Play \n")
  print("r for ⛰️ rock \np for 🧻 paper \ns for ✂️ scissors \n")
  playerOneAnswer = (input(f"What is youer anser 🤟🏻 {playerOne} 🤟🏻"))
  playerTwoAnswer = (input(f"What is youer anser 🤟🏻 {playerTwo} 🤟🏻"))
  
  if playerOne == "r" and playerTwo == "s":
    print(f"Rock smashes Scissors! ⛰️🔨✂️ Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerOne == "p" and playerTwo == "r":
    print(f"Paper covers Rock! 🧻🛡️⛰️ Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerOne == "s" and playerTwo == "p":
    print(f"Scissor cutts Paper! ✂️🔪🧻 Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerTwo == "r" and playerOne == "s":
    print(f"Rock smashes Scissors! ⛰️🔨✂️ Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "p" and playerOne == "r":
    print(f"Paper covers Rock! 🧻🛡️⛰️ Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "s" and playerOne == "p":
    print(f"Scissor cutts Paper! ✂️🔪🧻 Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "r" and playerOne == "r":
    print(f"Rock collides Rock! ⛰️💥⛰️ Careful you can start a fire that way! Try gain {playerOne} and {playerTwo}")
  elif playerTwo == "p" and playerOne == "p":
    print(f"Paper trash Paper! 🧻🚮🧻 No good, Paper and paper is just a waist and creates more trash! Pleas try again {playerOne} and {playerTwo} 🤷")
  elif playerTwo == "s" and playerOne == "s":
    print(f"Scissor collides with Scissors! ✂️💥✂️ Its a draw! {playerOne} and {playerTwo} try again 🤷")
else:
  print("Okay come back layter when you want to play! 💩")

Hello everyone I am new with python. I tried asking a question and they pointed me here so I was wondering if you guys can help me with my problem. Everything seems to be running fine until they answer true and false. Then nothing happens.

from getpass import getpass as input

print("👏 ROCK ⛰️, PAPER 🧻, SCISSORCS ✂️ 👏 \n\n")

print("Welcome to the basic rock paper scissors game. Will add to it more when I learn more in the future :P \n\n")

playerOne = input("Hello, \n\nWhat is your name Player One? \n")
print()
playerTwo = input("Hello, \n\nWhat is your name Player 2? \n")

getAnswer = input(print(f"Welcome \n\n{playerOne} and {playerTwo} \n\nReady to play ⛰️ Rock(r), 🧻 Paper(p), ✂️ Scissors(s) \ny = Yes, n = No 😅 \n"))


if getAnswer == "y" or "yes":
  print("Okay Lets Play \n")
  print("r for ⛰️ rock \np for 🧻 paper \ns for ✂️ scissors \n")
  playerOneAnswer = (input(f"What is youer anser 🤟🏻 {playerOne} 🤟🏻"))
  playerTwoAnswer = (input(f"What is youer anser 🤟🏻 {playerTwo} 🤟🏻"))
  
  if playerOne == "r" and playerTwo == "s":
    print(f"Rock smashes Scissors! ⛰️🔨✂️ Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerOne == "p" and playerTwo == "r":
    print(f"Paper covers Rock! 🧻🛡️⛰️ Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerOne == "s" and playerTwo == "p":
    print(f"Scissor cutts Paper! ✂️🔪🧻 Congratulation's {playerOne}, Better try again next time {playerTwo}")
  elif playerTwo == "r" and playerOne == "s":
    print(f"Rock smashes Scissors! ⛰️🔨✂️ Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "p" and playerOne == "r":
    print(f"Paper covers Rock! 🧻🛡️⛰️ Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "s" and playerOne == "p":
    print(f"Scissor cutts Paper! ✂️🔪🧻 Congratulation's {playerTwo}, Better try again next time {playerOne}")
  elif playerTwo == "r" and playerOne == "r":
    print(f"Rock collides Rock! ⛰️💥⛰️ Careful you can start a fire that way! Try gain {playerOne} and {playerTwo}")
  elif playerTwo == "p" and playerOne == "p":
    print(f"Paper trash Paper! 🧻🚮🧻 No good, Paper and paper is just a waist and creates more trash! Pleas try again {playerOne} and {playerTwo} 🤷")
  elif playerTwo == "s" and playerOne == "s":
    print(f"Scissor collides with Scissors! ✂️💥✂️ Its a draw! {playerOne} and {playerTwo} try again 🤷")
  else:
    print("One of you have pressed the wrong key!")
elif getAnswer == "n" or "No": 
  print("Okay come back layter when you want to play! 💩")
else:
  print("You have pressed the wrong button!")

What do you mean by this?

After input yes or no. I tried putting them in int() but when you press 2 it goes straight to else. without int() n and y still doesnt work. yes works. when you put n for no it stops running.

getAnswer = input(print(f"Welcome \n\n{playerOne} and {playerTwo} \n\nReady to play ⛰️ Rock(r), 🧻 Paper(p), ✂️ Scissors(s) \ny = Yes, n = No 😅 \n"))

if you say yes and it works then the first questions is requesting the t or f questions perfectly then stops running

print("r for ⛰️ rock \np for 🧻 paper \ns for ✂️ scissors \n")
  playerOneAnswer = (input(f"What is youer anser 🤟🏻 {playerOne} 🤟🏻"))
  playerTwoAnswer = (input(f"What is youer anser 🤟🏻 {playerTwo} 🤟🏻"))

I’m not sure what you mean. Here’s what I see

(I inputted “r” and “p”)

exactly it doesn’t print out what is true. and if you hit no on the first question it skips the the else statement as well. idk what I am doing wrong in my code.

That is because a string that is not empty always evaluates to True. So here

Python is reading your code like this

if (getAnswer == "y") or ("yes")

And since "yes" will always be True, the else statement is never reached.

So instead, you can check if the first letter of getAnswer is a y

if getAnswer[0] == "y"

Now the only problem is that the user might not have inputted any characters at all, so this would give an error. So first check if the user inputted anything.

if not getAnswer: # Empty strings will always be False
    print("Please input something")
elif getAnswer[0] == "y": # Check if the first letter of getAnswer is a "y"
    ...
elif getAnswer[0] == "n":
    print("Okay come back later when you want to play!")
else:
    print("You have pressed the wrong button!")

Now honestly I don’t see why you ask the user if they’re ready, you can just get rid of that entirely.

You’re checking the wrong variables.

Here you define playerOneAnswer and playerTwoAnswer.

But here you’re not checking for playerOneAnswer, you’re just checking for playerOne which is the name of the player, not their answer.