Welcome to the Get Help category!
Working on a banking app. Here is my code below.
The error message reads:
Traceback (most recent call last):
File “c:\Users\Andrew\Desktop\Codecademy\Python\Python_Projects\bank_account_project\Bank_Account.py”, line 90, in
User(“Strikeouts, ‘27’, ‘2790’”)
TypeError: User.init() missing 2 required positional arguments: ‘pin’ and ‘password’
Can someone tell me what is going on and where I went wrong?
# class zone
class BankAccount(object):
balance = 0
def __init__(self, name):
self.name = name
def __repr__(self):
return f"Welcome {self.name} Your current balance is: {self.balance}"
def show_balance(self):
print(f"Total balance is {self.balance:.2f}")
def deposit(self, amount):
if amount <= 0:
print("Error: Deposit must be a number greater than 0!")
return
else:
print(f"Depositing {amount}")
self.balance += amount
self.show_balance()
def withdraw(self, amount):
if amount > self.balance:
print("Insufficent funds! Please input a withdraw amount less than your current balance!")
return
else:
print(f"Withdrawing {amount}")
self.balance -= amount
self.show_balance()
class User:
def __init__(self, name, pin, password):
self.name = name
self.pin = pin
self.password = password
def change_name(self, new_name):
self.name = new_name
return new_name
def change_pin(self, new_pin):
self.pin = new_pin
return new_pin
def change_password(self, new_password):
self.password = new_password
return new_password
class BankUser(User):
def __init__(self, name, pin):
self.name = name
self.pin = pin
# super().__init__(name, pin, password)
# self.balance = 0
def show_balance(self):
print(self.name + " has an account balance of: " + str(self.balance))
def withdraw(self, amount):
self.balance -= amount
def deposit(self, depositamount):
self.balance += depositamount
def transfer_money(self, user, amount):
user_input = input("Please insert your pin for the transfer ")
if self.pin == user_input:
bill_gates.balance += amount
steve_jobs.balance -= amount
return True
else:
print("Invalid passcode.")
return False
return True
my_account = BankAccount("Andrew Stribling")
print(my_account)
my_account.show_balance()
my_account.deposit(2000.557945574)
my_account.withdraw(1000)
my_account.__repr__()
# Running the App Zone
User("Strikeouts, '27', '2790'")
# Github will be used to update the string formatting method.
# on task 11 we use the self. keyword to tell python to access the class. if we don't use the self keyword, it will not know where to pull information from. it is similar to the this keyword in javascript. This goes for running methods in objects, and using variables inside of the objects. you need to use the self keyword when the error statement says this is not defined in most cases.
# when working with objects, and its not interpreting my variables. I may need to use the self.variable name for it to recognize it due to scoping issues.
# %s is used as a placeholder the % is used as an ender of the string formatting and the variables need to be placed immediately afterwards in the order of necessary apperance.
# on this line we are taking the characteristics of the parent.
# we tell the computer to go get the parents informaiton on this line.```