(Python) How do I write code?

Asked 2 years ago, Updated 2 years ago, 128 views

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)
        ##I don't know how to code this place


newManager = AccountManager()
Name = input ("Enter account name :")
money=input ("Enter the deposit amount :")
newManager.newAcc()

I want to have the AccountManager.newAcc method create an instance of an Account class with the entered Name as its name

If account1 is entered in Name and money, The newManager.newAcc() is

I'd like to write to do something like account1 = account(money).

How do I write this?

class method object instance

2022-09-22 12:27

1 Answers

I think we need to learn more about class and object orientation.

I think you want to keep the Account Manager as a singleton object...I don't know because the question has no purpose.

First of all, please refer to the code below and proceed with the related learning.

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()


2022-09-22 12:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.