24th Jun 2021, 9:33 PM
Waithaka Waweru
Waithaka Waweru - avatar
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")
25th Jun 2021, 5:21 AM
Mohammad Anish
+ 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")
24th Jun 2021, 9:52 PM
Abhay
Abhay - avatar
+ 2
25th Jun 2021, 6:32 AM
Waithaka Waweru
Waithaka Waweru - avatar
+ 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))
25th Jun 2021, 9:15 AM
Shadoff
Shadoff - avatar