0
How do we write an calcule program between two variables ?
4 ответов
+ 9
sorry, but what is calcule?
+ 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()
+ 9
I guess you have obtain your answer.
+ 1
it is calculation : Mathematical calculations