write a simple python code to take in input from the user to calculate these arithmetic function these anthmetical function 4) addition ,subtraction multiplication, Division using variable and value
This code will prompt the user to enter two numbers and then calculate the addition, subtraction, multiplication, and division of those numbers. It also checks for division by zero to avoid errors.
Answers & Comments
Verified answer
Sure, here's a simple Python code that takes user input to perform addition, subtraction, multiplication, and division using variables and values:
```python
# Input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Perform arithmetic operations
addition_result = num1 + num2
subtraction_result = num1 - num2
multiplication_result = num1 * num2
# Check for division by zero
if num2 != 0:
division_result = num1 / num2
else:
division_result = "Cannot divide by zero"
# Display the results
print("Addition result:", addition_result)
print("Subtraction result:", subtraction_result)
print("Multiplication result:", multiplication_result)
print("Division result:", division_result)
```
This code will prompt the user to enter two numbers and then calculate the addition, subtraction, multiplication, and division of those numbers. It also checks for division by zero to avoid errors.