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?
@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!
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.
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 + '.')
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.
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
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
David is the one who taught the lessons in the videos
exactly what i needed, awesome thanks !
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 + '.')
Tip: use random.choice(list)
instead of random.randint
, it saves you from if statements