python - 如何将 +1 添加到函数之间的值

标签 python user-accounts

我想为刚刚注册帐户的每个用户添加一个 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,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()

最佳答案

注意你的 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,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()
我试图保持其他一切不变,但老实说我不确定你的 flag变量是为了。

关于python - 如何将 +1 添加到函数之间的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67242730/

相关文章:

linux - 使用 cgroup 将每个客户群的 CPU 使用率限制为 25%

python - 如何让 PySerial 接受 921600 波特率

python - BOTO3 DynamoDB 错误 : delete an item from a LIST attribute in a dynamodb table

javascript - 在 Meteor 中使用 Jasmine 进行单元测试注册用户方法

java - 如何在与 Firebase 链接的 Android Studio 中显示我的应用程序的所有在线用户?

PHP注册表打印错误

oracle - 在 Oracle 中,如何更改名称中包含特殊字符的用户?

python - 如何使用 python API 为 Mechanical Turk 中的批处理设置多个资格标准

python - 敌人角色被游戏背景 overdraw

python - 加快 Python 循环追加速度