I am new to python and trying to create a small atm like project using classes. I wanna have the user ability to input the amount they want to withdraw and if the amount exceeds the current balance, it prints out that you cannot have negative balance and asks for the input again.
class account:
def __init__(self,owner,balance):
self.owner = owner
self.balance = balance
# self.withdraw_amount = withdraw_amount
# self.deposit_amount = deposit_amount
print("{} has {} in his account".format(owner,balance))
def withdraw(self,withdraw_amount):
withdraw_amount = int(input("Enter amount to withdraw: "))
self.withdraw_amount = withdraw_amount
if self.withdraw_amount > self.balance:
print('Balance cannot be negative')
else:
self.final_amount = self.balance - self.withdraw_amount
print("Final Amount after Withdraw " + str(self.final_amount))
def deposit(self,deposit_amount):
deposit_amount = int(input("Enter amount to Deposit: "))
self.deposit_amount = deposit_amount
self.final_balance = self.balance + self.deposit_amount
print("Final Amount after Deposit " + str(self.final_balance))
my_account = account('Samuel',500)
my_account.withdraw(withdraw_amount)
But i am getting the followng error : NameError: name 'withdraw_amount' is not defined
Can someone please point out what i am doing wrong and how can i fix it? Thank you.
withdraw_amountis not defined beforemy_account.withdraw(withdraw_amount), Trymy_account.withdraw(int(input("Enter amount to withdraw: ")))and remove theinput()call from the method.deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-5.7ubuntu no longer supports 16.04 as of last month, so don't expect the ubuntu repositories to have any more updates