添加尚未定义的对象

时间:2018-03-04 04:52:23

标签: python

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)

1 个答案:

答案 0 :(得分:1)

你在找这样的东西吗?

Customer

这将继续将CustomerList添加/修改为 var data = 'test' ,直到用户输入0。