0

How do we write an calcule program between two variables ?

1st Apr 2017, 2:32 PM
mohamed
mohamed - avatar
4 ответов
+ 9
sorry, but what is calcule?
1st Apr 2017, 7:07 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 9
#Choose an operation first, then two numbers u want to perform it on. #Returns the sum of num1 and num2 def add(num1,num2): return num1 + num2 #Returns the result of subtracting num1 from num2 def subt(num1,num2): return num1 - num2 #Returns the result of multiplying num1 and num2 def mul(num1,num2): return num1*num2 def div(num1,num2): return num1/num2 def main(): operation=input("what do you want to do (+,-,*,/):\n") if(operation != '+' and operation != '-' and operation != '*' and operation != '/'): print ("invalid expression") else: var1=int(input("Enter num1:\n")) var2=int(input("Enter num2:\n")) if(operation=='+'): print(add(var1,var2)) elif (operation=='-'): print(subt(var1,var2)) elif (operation=='*'): print(mul(var1,var2)) else: print(div(var1,var2)) main()
1st Apr 2017, 7:11 PM
mr.Frechman
mr.Frechman - avatar
+ 9
I guess you have obtain your answer.
1st Apr 2017, 8:44 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 1
it is calculation : Mathematical calculations
1st Apr 2017, 7:13 PM
mohamed
mohamed - avatar