Untitled

mail@pastecode.io avatar
unknown
plain_text
7 days ago
900 B
4
Indexable
Never
def add(x,y):
 return x+y
def subtract(x,y):
 return x-y
def multiply(x,y):
 return x*y
def divide(x,y):
 return x/y
print("Select Operation")
print("1.Addition")
print("2.subtraction")
print("3.Multiplication")
print("4.Division")
while True:
 choice=input("Enter Your Choice (1/2/3/4):")
 if choice in('1','2','3','4'):
 try:
 num1=float(input("Enter First Number:"))
 num2=float(input("Enter Second Number:"))
 except ValueError:
 print(" Invalid Input.Please enter a number")
 continue
 if choice=='1':
 print(num1,"+",num2,"=",add(num1,num2))
 elif choice=='2':
 print(num1,"-",num2,"=",subtract(num1,num2))
 elif choice=='3':
 print(num1,"*",num2,"=",multiply(num1,num2))
 elif choice=='4':
 print(num1,"/",num2,"=",divide(num1,num2))
 next_calculation=input("lets do next calculation(yes/no):")
 if next_calculation=='no':
 break
 else:
 print("Invalid Input"
Leave a Comment