-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Example21.py
More file actions
27 lines (23 loc) · 1.05 KB
/
Class_Example21.py
File metadata and controls
27 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Define a class called BankAccount that accepts the name you want associated with your bank account in a string, and an integer that represents the amount of money in the account. The constructor should initialize two instance variables from those inputs: name and amt. Add a string method so that when you print an instance of BankAccount, you see "Your account, [name goes here], has [start_amt goes here] dollars." Create an instance of this class with "Bob" as the name and 100 as the amount. Save this to the variable t1.
"""
class BankAccount:
"""
Provides the information related about the bank
"""
def __init__(self, name, amount):
"""
Initializes the variables
:param name: assigns to name
:param amount: assigns to amount
"""
self.name = name
self.amount = amount
def __str__(self):
"""
Represents the account in the form of string
:return:
"""
return f"Your account, {self.name}, has {self.amount} dollars"
t1=BankAccount("Bob",100)
print(t1)