From c78feffd0bfc774342b4c476a4b02d23740df363 Mon Sep 17 00:00:00 2001 From: aditin1202 <143726861+aditin1202@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:24:18 +0530 Subject: [PATCH] Update calculator.py --- calculator.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/calculator.py b/calculator.py index 2550c49..4102674 100644 --- a/calculator.py +++ b/calculator.py @@ -5,19 +5,24 @@ # Asks user for 2 operands and 1 operator # Returns output of this operation -a=input("Enter number 1 : ") -o=input("Enter operator : ") -b=input("Enter number 2 : ") +a=int(input("enter number 1:")) +o = input("Enter operator: ") +b =int(input("Enter number 2: ")) -if o[0] in [ '+','-','*','/' ]: + +if o[0] in ['+', '-', '*', '/']: if o[0] == '+': out = a + b - elif o[0] == '-': - out = a - b + elif o[0] == '*': out = a * b elif o[0] == '/': out = a//b - print("Output : ",out) + # Check for division by zero + if b == 0: + print("Error not allowed.") + exit() + out = a / b + print("Output: ", out) else: - print("Error : Invalid Operator") + print("Error: Invalid Operator")