Python - having multiple "if" statements
Basically, I'm trying to make a basic login program, that asks the user
for a username and password, and records any right or wrong text in a
logfile. The problems I'm having are that when I try to have more than 1
username and password combination I get syntax errors. Sorry if I've not
explained this well enough, hopefully you know what I'm on about because
of my code. I'm aware this code is terrible and messy and basic, but I'm
about 1 week into Python.
#login program
output = open("logfile.txt", 'a')
login = input("please enter the correct username and password\n")
a = "username password"
b = "username1 password1"
if a in login:
print("successfully logged in")
import time
localtime = time.asctime(time.localtime(time.time()))
output.write("Somebody successfully logged in at ")
output.write(localtime)
output.write("\n")
output.close()
if b in login:
print("successfully logged in")
import time
localtime = time.asctime(time.localtime(time.time()))
output.write("Somebody successfully logged in at ")
output.write(localtime)
output.write("\n")
output.close()
else:
print("access denied.")
import time
output = open("logfile.txt", "a")
localtime = time.asctime(time.localtime(time.time())
output.write("Somebody unsuccessfully logged at ")
output.write(localtime)
output.write("\n")
output.close()
No comments:
Post a Comment