+ 1

I want to make a calculator by definining function. Can you help me to fix the problem?

https://code.sololearn.com/cIMazO8JCByE/?ref=app

15th Dec 2017, 12:16 PM
Aritra Roy
Aritra Roy - avatar
3 Answers
+ 10
Your code was poorly formatted and indented, which is intolerable in python. Correct code: a = input() x = int(input()) y = int(input()) def sum(a,b): p = (a+b) print(p) def substract(a,b): p = (a-b) print(p) def division(a,b): if b != 0: p = (a/b) print(p) def multiply(a,b): p = (a*b) print(p) if a == "sum": sum(x,y) elif a == "substract": substract(x,y) elif a == "multiply": multiply(x,y) elif a == "division": division(x,y) else: print("not available")
15th Dec 2017, 12:40 PM
Cool Codin
Cool Codin - avatar
+ 6
You must first defining function and then call it, like this: def sum(a,b): p=(a+b) print (p) def substract(a,b): p=(a-b) print (p) def division (a,b): if b!=0: p= (a/b) print (p) def multiply(a,b): p=(a*b) print (p) a= input () x=int(input ()) y= int(input ()) if a =="sum": sum(x,y) elif a=="substract": substract(x,y) elif a=="multiply": multiply(x,y) elif a=="division": division(x,y) else: print ("not available")
15th Dec 2017, 12:43 PM
Vukan
Vukan - avatar
0
thank you all.
15th Dec 2017, 12:47 PM
Aritra Roy
Aritra Roy - avatar