Record#
- Today learned def. def is to define a function, which can be repeatedly called in the code.
- The naming of functions can include letters, numbers, underscores, etc., cannot start with a number, cannot have spaces, and cannot be the same as Python built-in functions.
- Pay attention to the indentation of the context code of the function. Python is really a language that strictly requires indentation.
- Use functions to create a user login interface to verify the username and password. When there is an error, prompt the error and ask for re-entry.
CODE#
print("User login page")
print()
def ulogin():
u = ""
p = ""
while True:
u = input("Enter username:")
p = input("Enter password:")
if u == "user" and p == "pass":
print("Welcome, user!")
break
else:
print("Incorrect username or password, please try again")
continue
ulogin()