Hope this code may help you
def add(a,b):
print(a+b)
def subract(a,b):
print(a-b)
def multipy(a,b):
print(a*b)
def divide(a,b):
print(a/b)
ch="y"
while ch=="y" or ch=="Y":
x = float(input("first number : "))
y = float(input("second number: "))
print(".....MENU.......\n 1.Add\n 2.Subtract\n 3.Multiply\n 4.Divide\n")
op=int(input("Enter your choice : "))
if op==1:
add(x,y)
elif op==2:
subract(x,y)
elif op==3:
multipy(x,y)
elif op==4:
divide(x,y)
else: print("invalid Choice")
ch=input("Do you want to continue?(Y/y) : ")
you may get output as:
first number : 10
second number: 20
.....MENU.......
1.Add
2.Subtract
3.Multiply
4.Divide
Enter your choice : 1
30.0
Do you want to continue?(Y/y) : y
first number : 20.7
second number: 13.2
.....MENU.......
1.Add
2.Subtract
3.Multiply
4.Divide
Enter your choice : 2
7.5
Do you want to continue?(Y/y) : y
first number : 3.6
second number: 7.9
.....MENU.......
1.Add
2.Subtract
3.Multiply
4.Divide
Enter your choice : 3
28.44
Do you want to continue?(Y/y) : y
first number : 45
second number: 7
.....MENU.......
1.Add
2.Subtract
3.Multiply
4.Divide
Enter your choice : 4
6.428571428571429
Do you want to continue?(Y/y) : n
Process finished with exit code 0
this is a simple basic problem …
First you have to try your own code then if you get any error while solving. You have to ask Don’t just directly post your question..
2
solved python calculator with two float numbers as parameters [closed]