如何在试图伪装密码时更改字符串的字母?

2024-03-29 09:58:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Python3.5.1中创建一个简单的用户名和密码脚本,但我不知道如何让用户输入一个密码,然后用星号将其覆盖,使其无法读取

这是我目前的代码:

import time
print ("Hello!")
time.sleep(1)
print ("Welcome to the Username and Password python test!")
time.sleep(3)
Username = input ("Please enter your desired Username ")
time.sleep(1)
print ("Your username is "+ Username)
time.sleep(1)
Q1 = input ("Is this correct? 'Y' or 'N' ")
if Q1 == "N":
    Q2 = input ("Would you like to change it? ")
    if Q2 == "Y": Username = input ("Please re enter your Username ")
    print ("Your Username is now "+ Username)
    time.sleep(2)
    print ("You cannot change your Username now")
    time.sleep(2)
if Q1 == "Y": time.sleep(1)
Password = input ("Please input your Password ")
time.sleep(3)
Q3 = input ("Please enter your Username ")
if Q3 == Username:
    time.sleep(1)
    Q4 = input ("Please now input your Password ")
    time.sleep(1)
    if Q4 == Password:
        print ("Correct")
        time.sleep(2)
        print ("Thank you for using the Username and Password python test")
    else:
        print ("Incorrect Password")
else:
    print ("Username not found")

Tags: theto密码inputyouriftimeusername