0

当座預金口座をシミュレートする Python 3.0 の OOP プログラムに取り組んでいますが、理解できないバグに遭遇しました。ここにあります: プログラムの主要部分で、ユーザーに複数のオプション (exit、withdraw、deposit、create new account など) を与えました。ユーザーが「新しいアカウントの作成」を選択すると、プログラムはオブジェクトを作成し、変数名は別の変数でなければならず、変数でラベル付けされたオブジェクトから属性にアクセスする方法がわかりません.基本的に私が求めているのは、どうすればよいですかコンピューターがそれを追跡し、それを使用してオブジェクトの属性にアクセスできるように、変数名を変数にしますか? ここに私がこれまでに持っているプログラムがあります(それが役立つ場合?):

class Checking(object):
    """a personal checking acount"""

    def __init__(self , name, balance):
        print("a new checking acount has been created")
        self.name = name
        self.balance = balance


    def __str__(self):
        rep = "Balance Object\n"
        rep += "name of acount" + self.name + "\n"
        rep += "balance is " + self.balance + "\n"
        return rep


    def display(self):
        print("\nyour acount name is ",self.name)
        print("your balance is",self.balance)


    def deposit(self):
        amount = int(input("\nplease enter the amount of money you wish to diposit"))
        self.balance += amount
        print("\nthe balance of 'chris' is ", self.balance)

    def withdraw(self):
        amount = int(input("\nplease enter the amount you wish to withdraw "))
        while amount > self.balance:
            print("is an invalid amount")
            amount = int(input("\nplease enter the amount you wish to withdraw "))
        self.balance -= amount
        print("\nthe balance of 'chris' is ", self.balance)






    answer = None

    while answer != "0":
        answer = input("""what action would you like to take?
        0 exit
        1 deposit
        2 withdraw
        3 add an acount""")
        if answer == "1":
            input("ener your PIN").deposit()
        if answer == "2":
            input("enter your PIN ").withdraw()
        if answer == "3":
            input("enter num") = Checking(name = input("\nwhat do you want your acount name to be?"), balance = 0)
            input("enter you PIN").display()
            print(Checking)

    input("\n\npress enter to exit")
4

1 に答える 1