0% found this document useful (0 votes)
78 views

Python 3

This document defines custom exception classes for a banking ATM program. MinimumDepositError is raised if a deposit amount is less than 2000. MinimumBalanceError is raised if a withdrawal would bring the balance below 500. The Bank_ATM function handles deposits and withdrawals, updating the balance, and raises the custom exceptions if deposit or withdrawal amounts are invalid.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Python 3

This document defines custom exception classes for a banking ATM program. MinimumDepositError is raised if a deposit amount is less than 2000. MinimumBalanceError is raised if a withdrawal would bring the balance below 500. The Bank_ATM function handles deposits and withdrawals, updating the balance, and raises the custom exceptions if deposit or withdrawal amounts are invalid.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class MinimumDepositError(Exception):

def __init__(self, value):


self.value = value
def __str__(self):
return str(self.value)

class MinimumBalanceError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return str(self.value)

#balance = int(input())
#choice = int(input())
#amount = int(input())
def Bank_ATM(balance,choice,amount):
# Write your code here
#balance = int(input())
#choice = int(input())
#amount = int(input())
if (balance < 500):
print("As per the Minimum Balance Policy, Balance must be at least
500")
elif (choice == 1):
try:
if (choice == 1 and amount < 2000):
raise MinimumDepositError("The Minimum amount of Deposite should be
2000")
balance = balance + amount
print("Updated Balance Amount: " + str(balance))
#print("Updated Balace Amount: " + str(balance))
except MinimumDepositError as md:
print(md)
elif (choice == 2):
try:
if (choice == 2 and amount < 500):
raise MinimumBalanceError("You cannot withdraw this amount due to
Minimum Balace Policy")
balance = balance - amount
print("Updated Balance Amount: " + str(balance))
except MinimumBalanceError as mb:
print(mb)

class MinimumDepositError(Exception):
#__init__()
def __init__(self):
#message for MinimumDepositError
self.msg = ("The Minimum amount of Deposit should be 2000.")
super().__init__(self.msg)
#user defined Exception MinimumBalanceError
class MinimumBalanceError(Exception):
#__init__()
def __init__(self):
#message for MinimumBalanceError
self.msg = ("You cannot withdraw this amount due to Minimum Balance
Policy")
super().__init__(self.msg)
def Bank_ATM(balance,choice,amount):
# Write your code here
#if balance is less than 500
if balance < 500:
#raises ValueError
msg = ("As per the Minimum Balance Policy, Balance must be at least 500")
raise ValueError(msg)

#if deposit
if choice == 1:
#if deposit amount less than 2000
if amount < 2000:
#raises MinimumDepositError
raise MinimumDepositError
#otherwise
else:
#updates balance
balance = balance + amount
#prints updated balance
print("Updated Balance Amount: ", balance)

#if withdrawal
if choice == 2:
#if balance after withdrawal is less than 500
if balance - amount < 500:
#raises MinimumBalanceError
raise MinimumBalanceError
else:
#updates balance
balance = balance - amount

#prints updated balance


print("Updated Balance Amount: ", balance)

You might also like