19 lines
623 B
Python
19 lines
623 B
Python
# Question: Write a Python program to perform arithmetic calculation. The program should accept two operands and an operator, then display the result.
|
|
|
|
num1 = float(input("Enter first number: "))
|
|
num2 = float(input("Enter second number: "))
|
|
operator = input("Enter operator (+, -, *, /): ")
|
|
if operator == '+':
|
|
result = num1 + num2
|
|
elif operator == '-':
|
|
result = num1 - num2
|
|
elif operator == '*':
|
|
result = num1 * num2
|
|
elif operator == '/':
|
|
if num2 != 0:
|
|
result = num1 / num2
|
|
else:
|
|
result = "Error: Division by zero"
|
|
else:
|
|
result = "Error: Invalid operator"
|
|
print(f"Result: {result}") |