我正在尝试学习python,并且在编写简单的登录页面时遇到了问题。
def Login():
print("Login System")
print("\n")
print("1 - Login")
print("2 - Create an Account")
PassCheck = False
UserCheck = False
Login = False
selec = input("What do you want to do?: ")
if selec == '1':
print("Input your credentials")
usernameLog = input("Input you username: ")
usertxt = open("user.txt", "r")
if usernameLog == usertxt.read():
UserCheck = True
else:
UserCheck = False
usertxt.close()
passwordLog = input("Input you password: ")
passwordtxt = open("pass.txt", "r")
if passwordLog == passwordtxt.read():
PassCheck = True
else:
PassCheck = False
passwordtxt.close()
if UserCheck and PassCheck == True:
print('\n')
print('\n')
print('You Logged In')
else:
print('\n')
print('\n')
print('Username or password incorrect')
Login()
Login()
它以前工作过,只是停止工作了。它表示Login()函数不可调用。
答案 0 :(得分:0)
尝试更改Login变量的名称。最好将函数名称更改为小写。 也尝试下面的代码。我只是将(如果selec ==“ 1”)更改为(如果selec == 1)
def Login():
print("Login System")
print("\n")
print("1 - Login")
print("2 - Create an Account")
PassCheck = False
UserCheck = False
selec = input("What do you want to do?: ")
if selec == 1:
print("Input your credentials")
usernameLog = input("Input you username: ")
usertxt = open("user.txt", "r")
if usernameLog == usertxt.read():
UserCheck = True
else:
UserCheck = False
usertxt.close()
passwordLog = input("Input you password: ")
passwordtxt = open("pass.txt", "r")
if passwordLog == passwordtxt.read():
PassCheck = True
else:
PassCheck = False
passwordtxt.close()
if UserCheck and PassCheck == True:
print('\n')
print('\n')
print('You Logged In')
else:
print('\n')
print('\n')
print('Username or password incorrect')
Login()
Login()