0
Is there any way to get only one output?
I've made a login system in Python which gets the username and password to save in a external file called users.txt When I register there is no issue and my username and password is saved to the external file perfectly. But when I login and many users are registered in the file and I enter the right username and password in returns me Wrong Wrong Wrong Wrong You are logged in successfully! Is there any way that I can get only the correct text rather than getting these wrong texts before? I've attached my code in here: https://code.sololearn.com/cTxikjTWACzR/?ref=app
3 Respostas
+ 6
Create a new variable that checks whether the user is logged in or not.
https://code.sololearn.com/c18iqx9gAGYe/?ref=app
0
Use an external variable like this
def login():
username = input("Enter your Username: ")
password = input("Enter your Password: ")
login = 0 #external variable
for line in open("users.txt", "r").readlines():
login_info = line.split(", ")
if username == login_info[0] and password == login_info[1]:
login=1
if login == 1:
print("You are logged in successfully!")
else:
print("Wrong")
https://code.sololearn.com/cdM1EBWSzDmF/?ref=app
- 1
Try using a destructor 😁😉