From 51297e48aa188a880d06f3565114ff27c629a617 Mon Sep 17 00:00:00 2001 From: CHARAN Date: Thu, 22 Feb 2024 15:33:00 +0530 Subject: [PATCH] errors are gone --- calculator.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/calculator.py b/calculator.py index 2550c49..aa69112 100644 --- a/calculator.py +++ b/calculator.py @@ -1,23 +1,24 @@ -# -# calculator.py -# - # Asks user for 2 operands and 1 operator -# Returns output of this operation +# Returns output of this operationfdgdhd -a=input("Enter number 1 : ") -o=input("Enter operator : ") -b=input("Enter number 2 : ") +a = float(input("Enter number 1: ")) +o = input("Enter operator: ") +b = float(input("Enter number 2: ")) -if o[0] in [ '+','-','*','/' ]: - if o[0] == '+': +if o in ['+', '-', '*', '/']: + if o == '+': out = a + b - elif o[0] == '-': + elif o == '-': out = a - b - elif o[0] == '*': + elif o == '*': out = a * b - elif o[0] == '/': - out = a//b - print("Output : ",out) + elif o == '/': + if b != 0: + out = a / b + else: + print("Error: Division by zero") + out = None + if out is not None: + print("Output:", out) else: - print("Error : Invalid Operator") + print("Error: Invalid Operator")