NEED HELP WITH PYTHON CODE AND PLEASE KEEP OUTPUT SAME. Implement the following: 1) Create a class BankAccount with the attribute balance. 2) Create a BankAccount print method that prints the balance. 3) Create a class CheckingAccount which inherits from BankAccount. 4) CheckingAccount has an attribute numChecks. 5) In CheckingAccount override the BankAccount print method to also print numChecks. 6) Instantiate two objects, one of type BankAccount and one of type CheckingAccount. 7) Call the print functions for each object.   Example Output Balance: 100000 Balance: 200000    NumChecks: 10

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

NEED HELP WITH PYTHON CODE AND PLEASE KEEP OUTPUT SAME.

Implement the following:
1) Create a class BankAccount with the attribute balance.
2) Create a BankAccount print method that prints the balance.
3) Create a class CheckingAccount which inherits from BankAccount.
4) CheckingAccount has an attribute numChecks.
5) In CheckingAccount override the BankAccount print method to also print numChecks.
6) Instantiate two objects, one of type BankAccount and one of type CheckingAccount.
7) Call the print functions for each object.

 

Example Output
Balance: 100000
Balance: 200000    NumChecks: 10

Expert Solution
Step 1

Here we write a python program to perform simple bank operation like withdrawal and deposit of money with using oop concept.

> first of all we define a class BankAccount. Next our code is followed by defining a function using __init__. It is run as soon as an object of a class is instantiated. This __init__method is useful to do any initialization you want to do with object.

# BankAccount class 
class Bankaccount: 
    def __init__(self): 

# Function to withdraw the amount 
def withdraw(self): 
  amount = float(input("Enter amount to be withdrawn: ")) 
  if self.balance >= amount: 
   self.balance -= amount 
   print("\n You Withdrew:", amount) 
  else: 
   print("\n Insufficient balance ") 

>Here, we use the display function to show the remaining amount.

# Function to display the amount 
def display(self): 
  print("\n Net Available Balance =", self.balance) 

Step 2

Complete python code:-

# Python program to create Bankaccount class with a deposit() and a withdraw() function 
class Bank_Account: 
 def __init__(self): 
  self.balance=0
  print(" Welcome to the XYZ Bank") 

 def deposit(self): 
  amount=float(input("Enter amount to be Deposited: ")) 
  self.balance += amount 
  print("\n Amount Deposited:",amount) 

 def withdraw(self): 
  amount = float(input("Enter amount to be Withdrawn: ")) 
  if self.balance>=amount: 
   self.balance-=amount 
   print("\n You Withdrew:", amount) 
  else: 
   print("\n Insufficient balance ") 

 def display(self): 
  print("\n Net Available Balance=",self.balance) 

# Driver code 

# creating an object of class 
s = Bank_Account() 

# Calling functions with that class object 
b.deposit() 
b.withdraw() 
b.display() 

 

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Software Development
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education