如何隐藏玩家的输入

时间:2017-10-05 20:23:31

标签: python python-3.x python-3.6

我需要第二个用户无法看到第一个用户的输入,但当它告诉第二个用户输入时,第一个用户的输入就在他们面前

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")

输出结果为:

Player 1's turn: r
Player 2's turn: 
现在,玩家2只会使用纸张赢得比赛,所以我需要隐藏哪个玩家1以某种方式输入(我使用的是Python 3.6.1)

5 个答案:

答案 0 :(得分:1)

我正在使用Visual Studio代码编辑器,当我运行此代码时,它将清除“终端”窗口,该窗口将在不执行该命令的情况下执行。

AS ['+@DynamicColumnName+']

答案 1 :(得分:0)

您可以在此处使用getpass隐藏播放器1的输入,并使用input()为第二个玩家输入。

import getpass

player1 = getpass.getpass(prompt = "Player 1's turn:")
player2 = input("Player 2's turn")

答案 2 :(得分:0)

您可以尝试从控制台中删除所有文本,然后再询问播放器2的输入。

- hence I then tried to recompiled it with the provided Makefile but I get a whole buch of errors (pages or errors). So My intention was to fire up

请注意,如果在Windows上使用IDLE,此解决方案将无效,因为import os player1=input("Player 1's turn: ") os.system('cls') player2 = input("Player 2's turn: ") 不会与IDLE shell进行交互(this Stackoverflow answer中的更多详细信息)。

为此,你最好的选择似乎是打印了很多空行。您可以创建一个这样的函数,如下所示(来自上面的链接):

os.system()

答案 3 :(得分:0)

你可以使用一堆print()行来过去。

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

答案 4 :(得分:0)

这是一个对我没有任何问题的示例

import getpass

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

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

print(f'{user}, your password {password_hide} is {password_lenght} digits long')