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

Python Please include comments explaining and screen shot of output thank you! D

ID: 3811409 • Letter: P

Question

Python

Please include comments explaining and screen shot of output thank you!

Define a class for a restricted saving account that only permits three withdraw per months classRestrictedSavingsAccount(SavingsAccount):

"""This class represents a restricted savings account."""

MAX_WITHDRAWALS = 3

def __init__(self, name, pin, balance = 0.0):

"""Same attributes as SavingsAccount, but with a counter for withdrawals."""

def withdraw(self, amount):

"""Restricts number of withdrawals to MAX_WITHDRAWALS."""

def resetCounter(self):

self._counter = 0

Explanation / Answer

#!/usr/bin/python
class RestrictedSavingsAccount(SavingsAccount):
   """This class represents a restricted savings account."""
   MAX_WITHDRAWALS = 3
   def __init__(self, name, pin, balance = 0.0):
       """Same attributes as SavingsAccount, but with a counter for withdrawals."""
       self.name = name   #Assigns the passed parameter name to class variable name.
       self.pin = pin       #Assigns the passed parameter pin to class variable pin.
       self.balance = balance   #Assigns the passed parameter (if passed) balance to class variable balance.

   def withdraw(self, amount):  
       """Restricts number of withdrawals to MAX_WITHDRAWALS."""
       if self._counter < MAX_WITHDRAWALS:   #If the number of withdrawals as of now is less than MAX_WITHDRAWALS
           self.balance -= amount   #Withdraw the specified amount.
           self._counter += 1       #Increment the counter for the withdrawals.
       else:   #If not.
           print 'You reached the max withdrawals for this month.'   #Inform that maximum withdrawals for the month reached.
           print 'No withdrawals permitted for now.'  
   def resetCounter(self):   #Resets the withdrawal counter, at the end of month.
       self._counter = 0