0
Someone help me debug this code
4 ответов
+ 1
Code is debugged and also done some minor changes for better appearance
first_number = int(input("Entered First Number: "))
print(first_number)
second_number = int(input("Entered Second Number: "))
print(second_number)
operator = input("Entered Operator: ")
print(operator)
print('\n')
print('What is the solution of', first_number,operator,second_number,'?')
def add(first_number, second_number ):
result = first_number + second_number
print('Ans:',first_number,operator,second_number,'=', result)
def sub(first_number, second_number ):
result = first_number - second_number
print('Ans:',first_number,operator,second_number,'=', result)
def mul(first_number, second_number ):
result = first_number * second_number
print('Ans:',first_number,operator,second_number,'=', result)
def div(first_number, second_number ):
result = first_number / second_number
print('Ans:',first_number,operator,second_number,'=', result)
if operator == "+":
add(first_number,second_number)
elif operator == "-":
sub(first_number,second_number)
elif operator == "*":
mul(first_number,second_number)
elif operator == "/":
div(first_number,second_number)
else:
print("Invalid Operator")
+ 8
From line 24,
if operator == "+":
add(first_number,second_number)
elif operator == "-":
sub(first_number,second_number)
elif operator == "*":
mul(first_number,second_number)
elif operator == "/":
div(first_number,second_number)
else:
print("Invalid Operator")
+ 2
Thank you Abhay Mohammad Anish
+ 2
def check(x,y,z):
if z=="+":
res = x+y
elif z=="-":
res = x-y
elif z=="/":
if y==0:
res == "can not divide to zero"
else:
res = x/y
elif z=="*":
res = x*y
else:
res = "unknown operator"
return res
num1=int(input())
op = input()
num2 int(input())
print(check(num1,num2,op))