如何解决如何将 +1 添加到函数之间的值
我想为每个刚刚注册帐户的用户添加一个 id。 id 的工作方式就像第一个用户注册将有 1(number) 作为他或她的 id,第二个用户将有 2,第三个将有 3,依此类推。第一个用户 id 为 1 没有问题,但是当第二个、第三个和更多用户注册时,他们的 id 仍然保持为 1。有没有办法让我继续为下一个用户 id 加 1?>
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,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()
解决方法
请注意您的 customer_list
的长度如何始终等于您添加的最后一位客户的 ID。您可以简单地使下一个客户的 id 等于 customer_list
的长度加一。
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,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()
我尽量不影响其他所有内容,但老实说,我不确定您的 flag
变量的用途。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。