Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, Please see question below. It is an OOB question in the Python language. I w

ID: 3781383 • Letter: H

Question

Hi, Please see question below. It is an OOB question in the Python language. I would be grateful for any help with this question.

This question tests your understanding of Object Oriented Programming. The following code defines the start of a class to represent bank accounts:

class BankAccount(object):

interest_rate = 0.3

def __init__(self, name, number, balance):

self.name = name

self.number = number

self.balance = balance

return

(a) Name the class variables and the instance variables in the given code.

(b) Add instance methods called deposit() and withdraw() which increase and decrease the balance of the account. Make sure the withdraw() method doesn’t allow the account to go into overdraft. Add a third method called add interest() which adds interest to the balance (the interest should be the interest rate multiplied by the current balance).

(c) Create a subclass of BankAccount called StudentAccount. Every StudentAccount should have an overdraft limit of 1000. Write a constructor for the new class. Override the withdraw() method to make sure that students can withdraw money up to their overdraft limits.

Explanation / Answer

class BankAccount(object):

interest_rate = 0.3
def __init__(self, name, number, balance):
self.name = name
self.number = number
self.balance = balance
return

def deposit(self,amount):
   self.balance = self.balance+amount
   print "New balance is ",self.balance


def withdraw(self,amount):

    if self.balance <amount:
        print "balance is low"
    else:
        self.balance=self.balance-amount
def interest():
    self.balance=self.balance+self.balance*interest_rate/100

class StudentAccount(BankAccount):
   limit=1000

   def __init__(self, name, number, balance):
       super(StudentAccount,self).__init__(name, number, balance)
       return

   def withdraw(self,amount):

       if amount < 1000:
           if self.balance <amount:
                print "balance is low"
            else:
                self.balance=self.balance-amount
        else:
            print "Cannot remove more than 1000"

BO=BankAccount("Akshay",123,1000)
BO.deposit(100)

SO=StudentAccount("Raj",13,10000)
SO.withdraw(2000)
       
      


  
  


===========================================================

Output:

Akshay@akshay-Inspiron-3537:~/Chegg$ python bank.py
New balance is 1100
Cannot remove more than 1000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote