Write a python program that functions as a calculator. The program should run in an infinite loop. It should ask the user for two numbers and then offer four choices:
1) Add
2) Subtract
3) Multiply
4) Divide
Once it gets the operation from the user, it should call one of four functions to perform the operation and display the result. The functions should be placed in another module called calc.py
def Add(a,b):
return (a+b)
def Sub(a,b):
return (a-b)
def Mul(a,b):
return (a*b)
def Div(a,b):
return (a/b)
while(1):
a=int(input("Enter ist no. "))
b=int(input("Enter 2nd no. "))
print("1) Add")
print("2) Subtract")
print("3) Multiply")
print("4) Divide")
ch=int(input("Enter the choice to perform operation: "))
if(ch==1):
print("Addition of no. is :",Add(a,b))
elif(ch==2):
print("Subtraction of no. is :",Sub(a,b))
elif(ch==3):
print("Multiplication of no. is :",Mul(a,b))
elif(ch==4):
print("Division of no. is :",Div(a,b))
else:
print("Invalid choice")
Get Answers For Free
Most questions answered within 1 hours.