(파이썬) 어떻게 코드를 작성해야 할까요

조회수 558회
class Account:
    def __init__(self, money):
        self.__money = money

class AccountManager:
    def __init__(self):
        self.__accList[]
    def newAcc(self):
        global Name
        global money
        self.__accList.append(Name)
        ##이곳에 어떻게 코드를 작성해야 할지 모르겠습니다


newManager = AccountManager()
Name = input("계좌명을 입력하세요 :  ")
money=input("입금액을 입력하세요 :  ")
newManager.newAcc()

AccountManager.newAcc메소드가 입력받은 Name을 이름으로 가지는 Account 클래스의 인스턴스를 생성하게 만들고 싶습니다

만약 Name에 account1을, money에 입력받았다면, newManager.newAcc()가

account1 = Account(money)와 같은 일을 수행하도록 작성하고 싶습니다..

어떻게 작성해야 할까요..

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • 클래스와 객체지향 관련해서 학습을 더 진행해야 될 듯 하네요.

    AccountManager 를 싱글턴 객체로 유지하고 싶은 듯 한데...질문에 목적이 없으니 알수가 없습니다.

    일단 아래 코드를 참고하시고 관련 학습을 진행하시기 바랍니다.

    class Account:
        def __init__(self, money):
            self.__money = money
    
    class AccountManager:
        def __init__(self, name, money):
            self.name = name
            self.money = money
            self.__accList = []
    
        def newAcc(self):
            self.__accList.append(self.name)
            return Account(self.money)
    
    
    name = 'aaaa'
    money = 100
    
    newManager = AccountManager(name, money)
    acc = newManager.newAcc()
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)