0

I am doing this Project where I make methods in a class that work as a ATM Vestibule but I'm getting this error: This is my code:

class bank_account: def __init__(self, account_number, name, balance): self.account_number = account_number self.name = name self.balance = balance def withdraw(self, amount): if amount > self.balance: print("Insufficient Funds") else: self.balance = self.balance - amount def deposit(self, amount): if amount <= 0: print("Invalid Amount") else: self.balance = self.balance + amount def check_balance(self): print(self.balance) account_holder = bank_account(input("Enter your account number, name and balance: ")) transaction = input("Please enter what transaction you would like to do: (Withdraw, Deposit) ") amount = int(input("Enter the amount you would like to deposit or withdraw: ")) if transaction == 'withdraw' or 'Withdraw': account_holder.withdraw(amount) print(account_holder.check_balance()) elif transaction == 'deposit' or 'Deposit': account_holder.deposit(amount) account_holder = bank_account(input("Enter your account number, name and balance: ")) 

TypeError: init() missing 2 required positional arguments: 'name' and 'balance'

6
  • You need to ask for the name and the balance in seperate input statements. Commented Apr 30, 2020 at 0:52
  • 1
    Unrelated: you want a == b or a == c, not a == b or c. Commented Apr 30, 2020 at 0:58
  • @chepner what do you mean? Commented Apr 30, 2020 at 21:09
  • @TheMaker transaction == 'withdraw' or 'Withdraw' is always true, because 'Withdraw' is a non-empty string. Commented Apr 30, 2020 at 21:15
  • @chepner the error the OP is getting is related to the last line in his code. Have you noticed that? Commented Apr 30, 2020 at 21:26

2 Answers 2

3

Take inputs on seperate lines and pass them when creating the object

class bank_account: def __init__(self, account_number, name, balance): self.account_number = account_number self.name = name self.balance = balance def withdraw(self, amount): if amount > self.balance: print("Insufficient Funds") else: self.balance = self.balance - amount def deposit(self, amount): if amount <= 0: print("Invalid Amount") else: self.balance = self.balance + amount def check_balance(self): print(self.balance) account_number = int(input("Enter your account number: ")) # <=== Add this name = input("Enter your Name: ") # <=== Add this balance = int(input("Enter your balance: ")) # <=== Add this account_holder = bank_account(account_number, name, balance) # <=== Add this transaction = input("Please enter what transaction you would like to do: (Withdraw, Deposit) ") amount = int(input("Enter the amount you would like to deposit or withdraw: ")) if transaction == 'withdraw' or transaction == 'Withdraw': account_holder.withdraw(amount) print(account_holder.check_balance()) elif transaction == 'deposit' or transaction == 'Deposit': account_holder.deposit(amount) 
Sign up to request clarification or add additional context in comments.

Comments

1

I agree with faressalem's answer. You could also just change it in one line:

account_holder = bank_account(input("Enter your account number: "), input("Enter your name: "), input("Enter your balance: ")) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.