我正在制作一个扑克计划,为了让每个玩家的手保密,我想要合并密码,例如:
p1name = input("What would player 1 like to be called? ")
p1pass = input("Please enter a password to be used to play: ")
cardvalu = ["Ace of" , "Two of" , "Three of" , "Four of" ,
"Five of" , "Six of" , "Seven of" , "Eight of" ,
"Nine of" , "Jack of" , "Queen of" , "King of"] #These are the hands that the program will be picking when distributing cards
cardhand = ["Spades" , "Diamonds" , "Hearts" , "Clubs"] #These are the numbers the program will be picking when distributing cards
def p1hand(): #Next two lines show the cards for Player 1
print(random.choice(cardvalu),random.choice(cardhand))
print(random.choice(cardvalu),random.choice(cardhand))
然而,当要求玩家输入密码时,我意识到有人可以最小化图形并查看每个人的密码和手。所以,我想知道如何在指定的时间后打印一行文本。
答案 0 :(得分:1)
对于接收输入而不将其回显到屏幕的特定情况,您通常使用getpass.getpass
代替input
,因此用户的输入不会在第一个回显的地方。
否则,您需要处理移动光标(通过ANSI控制代码或使用the curses
module完全接管终端)然后用空格等覆盖通过屏幕回显的内容,这通常是更烦人。