Savings Account

Savings Account

Develop a Python script :                                                                                                       

Create a class SavingAccount having data  members as username and password .  This class contains a class attribute ‘balance’ and set this variable value as 20000  .

Create a 2 arguments parameterized constructor. Arguments should be : username and password

Create a function login (username, password)  in SavingAccount class .

Create function withdraw(amount) in SavingAccount class.

Create an object of SavingAccount class by invoking parameterized constructor by passing username and password as arguments.  These values should be hard coded ones.  Object name should be ‘sobj’ .

Call login(username,password)  function which will validate  for username and password.  Accept username and password from user andstore into the variables ‘username’ and ‘password’ respectively.

If the username and the password is equal to the one that you have entered when creating the object using parameterized constructor, then call withdraw (amount) function else print “Invalid username and password “ and return ‘False’.

For example:, Assume the class member attributes ‘username’ is set as ‘Admin’ and password is set us ‘123’ .  Then, in the login function, check if the username= “Admin” and password = 123 then call withdraw (amount) function return ‘True’.  Else print the message “Invalid username and password“ and return ‘False’.If login successful, then call withdraw(amount)  ask  the amount to withdraw, if amount to withdraw is greater than 20000 then display message as “In-sufficient funds to withdraw “  and return ‘False’Withdrawamount should get from the user and store into a variable named ‘amount’.

If amount to withdraw is less than 20000 then allow the amount to withdraw and after withdrawing show Amount withdrawal    and balance amount on console also the function should return ‘True‘. 

Note: Strictly follow the naming conventions for variables and functions as specified in the problem description.
Sample Input 1:Enter your name to Login Admin
Enter password 123
Enter amount to withdraw5000
Sample Output 1:
5000 is withdrew
15000 balance amount

Sample Input 2:Enter your name to Login developer
Enter password 123
Sample Output 2:
Invalid Username or password
Sample Input3:Enter your name to Login Admin
Enter password 123
Enter amount to withdraw25000
Sample Output 3:
Insufficient funds to withdraw

Code :-

class SavingAccount:
    def __init__(self,username,password):
    def login(self,username,password):
        if(self.username==username) and (self.password==password):
            return True
            print("Invalid username and password")
            return False
    def withdraw(self,amount):
        if amount>20000:
            print("In-sufficient funds to withdraw")
            return False
        elif amount<20000:
            return True
username=input("Enter your name to Login ")
password=input("Enter password ")
if x==True:
    amount=int(input("Enter amount to be withdraw"))
    if y==True:
        print(amount,"is withdrew")
        print(SavingAccount.balance,"balance amount")

Leave a Comment

Your email address will not be published. Required fields are marked *