Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . 10 Python programs to perform addition, subtraction, multiplication, and division of two numbers

10 Python programs to perform addition, subtraction, multiplication, and division of two numbers

Become More Then A coder | Learn & Start Coding Now.

here are ten Python programs to perform addition, subtraction, multiplication, and division of two numbers:


### 1. Addition:

```python
# Program 1: Addition of two numbers
num1 = 10
num2 = 5
result_addition = num1 + num2
print("Addition:", result_addition)
```

### 2. Subtraction:

```python
# Program 2: Subtraction of two numbers
num1 = 10
num2 = 5
result_subtraction = num1 - num2
print("Subtraction:", result_subtraction)
```

### 3. Multiplication:

```python
# Program 3: Multiplication of two numbers
num1 = 10
num2 = 5
result_multiplication = num1 * num2
print("Multiplication:", result_multiplication)
```

### 4. Division (Float Result):

```python
# Program 4: Division of two numbers (float result)
num1 = 10
num2 = 5
result_division_float = num1 / num2
print("Division (Float Result):", result_division_float)
```

### 5. Division (Integer Result):

```python
# Program 5: Division of two numbers (integer result)
num1 = 10
num2 = 5
result_division_integer = num1 // num2
print("Division (Integer Result):", result_division_integer)
```

### 6. Using Functions:

```python
# Program 6: Performing arithmetic operations using functions
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    return a / b

num1 = 10
num2 = 5
print("Addition:", add(num1, num2))
print("Subtraction:", subtract(num1, num2))
print("Multiplication:", multiply(num1, num2))
print("Division (Float Result):", divide(num1, num2))
print("Division (Integer Result):", divide(num1, num2))
```

### 7. Using Arithmetic Operators:

```python
# Program 7: Performing arithmetic operations using arithmetic operators
num1 = 10
num2 = 5
print("Addition:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
print("Division (Float Result):", num1 / num2)
print("Division (Integer Result):", num1 // num2)
```

### 8. Using Lambda Functions:

```python
# Program 8: Performing arithmetic operations using lambda functions
addition = lambda a, b: a + b
subtraction = lambda a, b: a - b
multiplication = lambda a, b: a * b
division_float = lambda a, b: a / b
division_integer = lambda a, b: a // b

num1 = 10
num2 = 5
print("Addition:", addition(num1, num2))
print("Subtraction:", subtraction(num1, num2))
print("Multiplication:", multiplication(num1, num2))
print("Division (Float Result):", division_float(num1, num2))
print("Division (Integer Result):", division_integer(num1, num2))
```

### 9. Using Map Function:

```python
# Program 9: Performing arithmetic operations using map function
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    return a / b

num1 = 10
num2 = 5
results = map(lambda func: func(num1, num2), [add, subtract, multiply, divide])
print("Results:", list(results))
```

### 10. Using Eval Function:

```python
# Program 10: Performing arithmetic operations using eval function
num1 = 10
num2 = 5
operations = ['num1 + num2', 'num1 - num2', 'num1 * num2', 'num1 / num2']
results = [eval(operation) for operation in operations]
print("Results:", results)
```

These programs perform addition, subtraction, multiplication, and division of two numbers using different approaches - directly using arithmetic operators, defining functions, using lambda functions, map function, and eval function. Feel free to replace the `num1` and `num2` variables with any desired numbers to perform the desired arithmetic operations.

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.