I want to add an id to each user that have just registered an account. The way the id works will be like the first user register will have 1(number) as his or her id, the second user will have 2, the third will have 3 and so on. There is no issue to have 1 for the first user id, but as the second, third and more user register, their id still remained as 1. Is there a way that I can keep on adding 1 to the next user id?
customer_list = []
def customer_page():
print('customer page accessed')
opt = input("press '0' to signup another account: ")
if opt == '0':
signup()
def signup_success(f,i,n,p):
f = 1
if f == 1:
i += 1
customer_list.append([i,n,p])
print(customer_list)
customer_page()
def signup():
username = input('please enter your username: ')
password = input('please enter your password: ')
flag = 0
id = 0
signup_success(flag,id,username,password)
signup()
Notice how the length of your customer_list
is always equal to the id of the last customer you added. You can simply make the id of the next customer equal to the length of customer_list
plus one.
customer_list = []
def customer_page():
print('customer page accessed')
opt = input("press '0' to signup another account: ")
if opt == '0':
signup()
def signup_success(f,n,p):
f = 1
if f == 1:
i = len(customer_list) + 1
customer_list.append([i,n,p])
print(customer_list)
customer_page()
def signup():
username = input('please enter your username: ')
password = input('please enter your password: ')
flag = 0
signup_success(flag,username,password)
signup()
I tried to leave everything else untouched, though I'm honestly not sure what your flag
variable is for.