26 lines
796 B
Python
26 lines
796 B
Python
# Question: Write a Python program to perform arithmetic calculation. The program should accept two operands and an operator, then display the result.
|
|
|
|
def main(num1: float, num2: float, operator: str) -> None:
|
|
if operator == '+':
|
|
result = num1 + num2
|
|
elif operator == '-':
|
|
result = num1 - num2
|
|
elif operator == '*':
|
|
result = num1 * num2
|
|
elif operator == '/':
|
|
if num2 == 0:
|
|
print("Error: Division by zero")
|
|
raise ZeroDivisionError
|
|
result = num1 / num2
|
|
else:
|
|
print("Error: Invalid operator")
|
|
raise ValueError("Invalid operator. Use +, -, *, or /.")
|
|
|
|
print(f"Result: {result}")
|
|
|
|
if __name__ == '__main__':
|
|
main(10, 5, '+')
|
|
main(10, 5, '-')
|
|
main(10, 5, '*')
|
|
main(10, 5, '/')
|