5

I need the second user to not be able to see the first user's input, but when it tells the second user to input, the first user's input is right in front of them

score=[0,0]
print("Welcome to Rock Paper Scissors! The score starts as",score)
while True:
    player1=input("Player 1's turn: ")
    player2=input("Player 2's turn: ")
    if (player1.lower() in ["rock","r","rick","rok","roc","rck"]):
        if (player2.lower() in ["scissors","s","scissor"]):
            score[0]=score[0]+1
            print("Player 1 wins! The score is now",score)
        if (player2.lower() in ["rock","r","rick","rok","roc","rck"]):
            print("It's a tie! The score remains",score)
        if (player2.lower() in ["paper","p","pap","piper"]):
            score[1]=score[1]+1
            print("Player 2 wins! The score is now",score)
    if (player1.lower() in ["scissors","s","scissor"]):
        if (player2.lower() in ["scissors","s","scissor"]):
            score[0]=score[0]+0
            print("It's a tie! The score remains",score)
        if (player2.lower() in ["rock","r","rick","rok","roc","rck"]):
            score[1]=score[1]+1
            print("Player 2 wins! The score is now",score)
        if (player2.lower() in ["paper","p","pap","piper"]):
            score[0]=score[0]+1
            print("Player 1 wins! The score is now",score)
    if (player1.lower() in ["paper","p","pap","piper"]):
        if (player2.lower() in ["scissors","s","scissor"]):
            score[1]=score[1]+1
            print("Player 2 wins! The score is now",score)
        if (player2.lower() in ["rock","r","rick","rok","roc","rck"]):
            score[0]=score[0]+1
            print("Player 1 wins! The score is now",score)
        if (player2.lower() in ["paper","p","pap","piper"]):
            score[0]=score[0]+0
            print("It's a tie! The score remains",score)
    print("N E X T    G A M E")

The output is:

Player 1's turn: r
Player 2's turn: 

now, player 2 would just use paper and win the game, so i need to hide what player 1 inputted somehow (I'm using Python 3.6.1)

bhansa
  • 7,282
  • 3
  • 30
  • 55
Aidan Christopher
  • 161
  • 2
  • 2
  • 10

5 Answers5

3

You can use getpass here, to hide the player 1 's input and use input() for the 2nd players input.

import getpass

player1 = getpass.getpass(prompt = "Player 1's turn:")
player2 = input("Player 2's turn")
bhansa
  • 7,282
  • 3
  • 30
  • 55
  • when I used the getpass, nothing happened. it was just blank, no "Player 1's turn" or anything showed up – Aidan Christopher Oct 09 '17 at 21:13
  • `Player 1's turn :········ Player 2's turn :random` This is the output you get when you use it, please describe more about your problem. – bhansa Oct 10 '17 at 05:14
2

I'm using Visual Studio Code Editor and when I run this code it clears the Terminal window where it executes without any issues.

import getpass, os

welcome = """
************************************************************
*                                                          *
*        Welcome to the Rock, Paper, Scissors Game!        *
*                                                          *
************************************************************
"""
print(welcome)

player1 = getpass.getpass('Rock, Paper, Scissors? ', stream = None)
os.system('cls')
user6903745
  • 5,267
  • 3
  • 19
  • 38
user2399539
  • 43
  • 1
  • 6
0

You can try erasing all the text from the console before asking Player 2 for their input.

import os
player1=input("Player 1's turn: ")
os.system('cls')
player2 = input("Player 2's turn: ")

Note that this solution would not work if using IDLE on Windows, since os.system() does not interact with the IDLE shell (more details in this Stackoverflow answer).

For that, your best bet seems to be printing a lot of blank lines. You can create a function that does so, like this (from the above link):

def cls(): print "\n" * 100
Antimony
  • 2,230
  • 3
  • 28
  • 38
  • Well it asks the first user and then when they have entered the input, it clears the screen. That is exactly how it worked for me. What did you get? – Antimony Oct 09 '17 at 23:47
  • This seems to be [a well-known problem](https://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window) with using IDLE on Windows. I tested this on Windows cmd and it works there. I'd suggest trying the top rated answer from that link. – Antimony Oct 10 '17 at 21:21
0

You can use a bunch of print() lines to get past it.

player1move=input()
print("\n"*100)
player2move=input()
print("\n"*100)
#calculate who won
#print result
0

Here is an example that worked for me without any issues:

import getpass

user = input('User: ')
password = getpass.getpass('Password: ')

password_length = len(password)
password_hide = ('*' * password_length)

print(f'{user}, your password {password_hide} is {password_length} digits long')
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Marius
  • 33
  • 1
  • 6