我尝试了几种不同的方法,但我似乎无法修复它。在底部,它只是创建.txt文件,但不添加任何变量并保持为空。然后它开始在shell中的其余代码下面打印用户名和密码。 Enters the username and password and prints below whilst the .txt file remains empty.
un = input("What is your username?")
npw = input("Please enter new password.")
npwc = input ("Please confirm new password")
if npwc == npw:
if npwc.isupper()== False:
if npwc.islower()== False:
if len(npwc) >= 8:
if str.isdigit(npwc) == False:
npw=npwc
print("Your paswsword has been changed")
else:
print("Your password must contain a number")
else:
print("Your password must contain at least 8 characters.")
else:
print("Your password must contain at least 1 upper case character.")
else:
print ("Passwords don't match")
pw = npwc
file=open("PasswordSheet.txt","a")
file.write(input(un, ", ", pw))
file.close()
答案 0 :(得分:2)
file.write(input(un + ", " + pw))
应该是
file.write(un + ", " + pw)