gpt4 book ai didi

python - 添加 undefined object

转载 作者:太空宇宙 更新时间:2023-11-03 14:03:23 25 4
gpt4 key购买 nike

def addAccount():
print ("You have chosen to add an account")
numAcc = 5
proceed = int(input("Please choose 1 to procedd. If you enter 0, the process will be cancelled.: "))
while (proceed != 0):
addName = str(input("Please enter the name of the new account: "))
addBirthday = str(input("Please enter the birthday of the user (month day, year) :"))
addAddress = str(input("Please enter the address of the user: "))
addHkid = str(input("Please enter the HK IDcard number: "))
addBalance = 0
numAcc = numAcc + 1
c6 = Customer (addName, addBirthday, addAddress, addHkid, addBalance)
CustomerList.append (c6)
break

我的 python 代码有这个代码。

我在上面定义了CustomerList,客户从c1调用到c5。

我想添加名为 c6 的新客户 --- 直到数量为止。

有没有办法让我更改一些代码或其他内容,以便能够将新客户添加到我的客户列表中?我试图使用 numAcc,这样每次 while 循环我都可以为该 numAcc 值添加 1,并使用该数字来添加帐户(作为在每个客户末尾添加的数字)。

我定义的客户是这样的:

c1 = Customer ("Jack", "Jan, 10th, 1996", "430 Davis Ct., San Francisco", "M8875895", 40000)
c2 = Customer ("Smith", "March 24th, 1997", "3-5 Tai Koo Shing, Hong Kong", "M3133242", 600)
c3 = Customer ("Suzy", "May 5th, 1995", "32 Clearwater Bay Ave. Hong Kong", "M8378644", 100000)
c4 = Customer ("Craig", "May 24th, 1993", "700 Powell Street, San Francisco", "M2314565", 70000)
c5 = Customer ("Vic", "September 21st, 1992", "1210 Freud Street, New York", "M1234569", 3400)

最佳答案

您正在寻找这样的东西吗?

def addAccount():
print ("You have chosen to add an account")
proceed = 1
while proceed != 0:
proceed = int(input("Please enter any number except 0 to proceed. If you enter 0, the process will be cancelled: "))
addName = str(input("Please enter the name of the new account: "))
addBirthday = str(input("Please enter the birthday of the user (month day, year) :"))
addAddress = str(input("Please enter the address of the user: "))
addHkid = str(input("Please enter the HK IDcard number: "))
addBalance = 0
CustomerList.append(Customer(addName, addBirthday, addAddress, addHkid, addBalance))

这将不断向 CustomerList 添加/修改 Customer,直到用户输入 0。

关于python - 添加 undefined object ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49092100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com