Validate Work Age,: Account Withdrawal

class InvalidAgeError(Exception):
    pass


def validate_age(age):
    if age >= 18 and age <=60:
        return True
    else:
        raise InvalidAgeError('Age should be between 18-60')


name = input('Enter Name:')
age = int(input('Enter Age:'))

try:
    validate_age(age)
    print('You can join Work')
except InvalidAgeError as e:
    print(e)

class InsufficientFundsError(Exception):
    pass

def withdraw(balance, amount):
    if amount > balance:
        raise InsufficientFundsError("Not enough funds")
    return balance - amount


balance = 5000
amount = int(input("Enter Amount: "))

try:
    balance = withdraw(balance, amount)
    print('Withdrawal successful')
    print('Remaining balance:', balance)
except InsufficientFundsError as e:
    print(e)

Similar Posts

Leave a Reply

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