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

  • Class 10 String Comparison ,Bitwise Operators,Chaining Comparisons

    String Comparison with Relational Operators in Python 💬⚖️ In Python, you can compare strings using relational operators (<, <=, >, >=, ==, !=). These comparisons are based on lexicographical (dictionary) order, which uses the Unicode code points of the characters. đź“– How String Comparison Works 🤔 Examples đź’ˇ Python Important Notes 📌 String comparison is…

  • positive lookahead assertion

    A positive lookahead assertion in Python’s re module is a zero-width assertion that checks if the pattern that follows it is present, without including that pattern in the overall match. It is written as (?=…). The key is that it’s a “lookahead”—the regex engine looks ahead in the string to see if the pattern inside…

  • Formatted printing

    C-Style String Formatting in Python Python supports C-style string formatting using the % operator, which provides similar functionality to C’s printf() function. This method is sometimes called “old-style” string formatting but remains useful in many scenarios. Basic Syntax python “format string” % (values) Control Characters (Format Specifiers) Format Specifier Description Example Output %s String “%s” % “hello” hello %d…

  • The print() Function in Python

    The print() Function in Python: Complete Guide The print() function is Python’s built-in function for outputting data to the standard output (usually the console). Let’s explore all its arguments and capabilities in detail. Basic Syntax python print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False) Arguments Explained 1. *objects (Positional Arguments) The values to print. You can pass multiple items separated by commas. Examples:…

  • What is list

    In Python, a list is a built-in data structure that represents an ordered, mutable (changeable), and heterogeneous (can contain different data types) collection of elements. Lists are one of the most commonly used data structures in Python due to their flexibility and dynamic nature. Definition of a List in Python: Example: python my_list = [1, “hello”, 3.14,…

  • Create lists

    In Python, there are multiple ways to create lists, depending on the use case. Below are the most common methods: 1. Direct Initialization (Using Square Brackets []) The simplest way to create a list is by enclosing elements in square brackets []. Example: python empty_list = [] numbers = [1, 2, 3, 4] mixed_list = [1, “hello”, 3.14,…

Leave a Reply

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