In this assignment, you will be creating an abstract class for a bank that will be used to create a regular class for a specific bank.
This class will contain the implementation of the abstract method from the abstract class.
- View -> Editor Layout -> Two Columns
- To view this file in Preview mode, right click on this README.md file and
Open Preview
- Select your code file in the code tree, which will open it up in a new VSCode tab.
- Drag your assessment code files over to the second column.
- Great work! You can now see instructions and code at the same time.
- Select your Python file in the Visual Studio Code file tree
- You can right click the file and select "Run Python File in Terminal" or run the file using the smaller
play button in the upper right-hand corner of VSCode.
(Select "Run Python File in Terminal" in the provided button dropdown)- Alternatively, you can follow lab instructions which use python3 commands to run your code in terminal.
-
Create a class called
Bank
and passABC
to it. -
Inside the class you have to define two methods:
-
2.1: Define a function called
basicinfo()
and add a print statement inside it saying
"This is a generic bank"
and returning the string"Generic bank: 0"
. -
2.2: Define a second function called
withdraw
and keep it empty by adding a pass keyword under it.
Make this function abstract by adding'@abstractmethod'
right above it.
-
-
Create another class called
Swiss
and pass the classBank
inside it. This means you are inheriting fromclass Bank
.- 3.1: Create a constructor for this class that initializes a class variable
bal
to1000
- 3.1: Create a constructor for this class that initializes a class variable
-
Override both functions from the Bank class:
basicinfo()
andwithdraw()
.-
4.1: Define a function called
basicinfo()
and add a print statement inside it stating“This is the Swiss Bank”
and returning a string with"Swiss Bank: "
followed by the current bank balance.
For example, ifself.bal = 80
, then it would return"Swiss Bank: 80"
-
4.2 Define a second function, called
withdraw
and pass one parameter to it (other thanself):
amount.
Amount represents the amount that will be withdrawn.- 4.2.1: Update the class variable bal by deducting the value of amount from it.
- 4.2.2: Print the value of amount giving output such as: “Withdrawn amount: 30"
- 4.2.3: Print the new balance giving an output such as: “New balance: 970”
- 4.2.4: Return the new balance
- Note: Make sure to verify that there is enough money to withdraw!
If amount is greater than balance, then do not deduct any money from the class variablebal
. Instead, print a statement saying"Insufficient funds"
, and return the original account balance instead.
-