From bafad5088ae06da8f57237c5913dfc1b43282af7 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Sun, 4 Feb 2024 12:06:23 +0530 Subject: [PATCH 1/2] add the type checking --- calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/calculator.py b/calculator.py index 2550c49..a7382da 100644 --- a/calculator.py +++ b/calculator.py @@ -5,9 +5,9 @@ # Asks user for 2 operands and 1 operator # Returns output of this operation -a=input("Enter number 1 : ") +a=int(input("Enter number 1 : ")) o=input("Enter operator : ") -b=input("Enter number 2 : ") +b=int(input("Enter number 2 : ")) if o[0] in [ '+','-','*','/' ]: if o[0] == '+': From 5c0c8e70b01987f0231eda0a0612be7fce630d00 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 22 Feb 2024 15:29:40 +0530 Subject: [PATCH 2/2] fixed bug --- calculator.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/calculator.py b/calculator.py index a7382da..5c7b674 100644 --- a/calculator.py +++ b/calculator.py @@ -10,14 +10,18 @@ b=int(input("Enter number 2 : ")) 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) -else: - print("Error : Invalid Operator") + if o[0] == '+': + out = a + b + elif o[0] == '-': + out = a - b + elif o[0] == '*': + out = a * b + elif o[0] == '/': + if b==0: + out="divide by zero error" + else: + out = a/b + + else: + print("Error : Invalid Operator") + print("Output : ",out)