Code icon

The App is Under a Quick Maintenance

We apologize for the inconvenience. Please come back later

Menu iconMenu iconAlgorithms and Data Structures with Python
Algorithms and Data Structures with Python

Project 1: Basic Calculator

3. Integrating Arithmetic Functions with Main Framework

Now, let's integrate these functions into our main framework. Within the main loop, after obtaining the two numbers from the user, we'll call the relevant function based on the operation the user has selected:

# ... previous code ...

    if user_input in ('add', 'subtract', 'multiply', 'divide'):
        x = float(input("Enter first number: "))
        y = float(input("Enter second number: "))

        # Integrate our functions with the chosen operation
        if user_input == 'add':
            print(add(x, y))
        elif user_input == 'subtract':
            print(subtract(x, y))
        elif user_input == 'multiply':
            print(multiply(x, y))
        elif user_input == 'divide':
            print(divide(x, y))

    else:
        print("Invalid Input")

# ... rest of the code ...

3. Integrating Arithmetic Functions with Main Framework

Now, let's integrate these functions into our main framework. Within the main loop, after obtaining the two numbers from the user, we'll call the relevant function based on the operation the user has selected:

# ... previous code ...

    if user_input in ('add', 'subtract', 'multiply', 'divide'):
        x = float(input("Enter first number: "))
        y = float(input("Enter second number: "))

        # Integrate our functions with the chosen operation
        if user_input == 'add':
            print(add(x, y))
        elif user_input == 'subtract':
            print(subtract(x, y))
        elif user_input == 'multiply':
            print(multiply(x, y))
        elif user_input == 'divide':
            print(divide(x, y))

    else:
        print("Invalid Input")

# ... rest of the code ...

3. Integrating Arithmetic Functions with Main Framework

Now, let's integrate these functions into our main framework. Within the main loop, after obtaining the two numbers from the user, we'll call the relevant function based on the operation the user has selected:

# ... previous code ...

    if user_input in ('add', 'subtract', 'multiply', 'divide'):
        x = float(input("Enter first number: "))
        y = float(input("Enter second number: "))

        # Integrate our functions with the chosen operation
        if user_input == 'add':
            print(add(x, y))
        elif user_input == 'subtract':
            print(subtract(x, y))
        elif user_input == 'multiply':
            print(multiply(x, y))
        elif user_input == 'divide':
            print(divide(x, y))

    else:
        print("Invalid Input")

# ... rest of the code ...

3. Integrating Arithmetic Functions with Main Framework

Now, let's integrate these functions into our main framework. Within the main loop, after obtaining the two numbers from the user, we'll call the relevant function based on the operation the user has selected:

# ... previous code ...

    if user_input in ('add', 'subtract', 'multiply', 'divide'):
        x = float(input("Enter first number: "))
        y = float(input("Enter second number: "))

        # Integrate our functions with the chosen operation
        if user_input == 'add':
            print(add(x, y))
        elif user_input == 'subtract':
            print(subtract(x, y))
        elif user_input == 'multiply':
            print(multiply(x, y))
        elif user_input == 'divide':
            print(divide(x, y))

    else:
        print("Invalid Input")

# ... rest of the code ...