11def add (number1 , number2 ):
2- """Add function."""
32 return number1 + number2
43
54def multiplication (number1 , number2 ):
6- """Multiplication function."""
75 return number1 * number2
86
7+ def division (number1 , number2 ):
8+ return number1 / number2
9+
10+ def subtract (number1 , number2 ):
11+ return number1 - number2
12+
13+
914print ("Select operation." )
1015print ("1. Add" )
1116print ("2. Multiply" )
1217print ("3. Divide" )
18+ print ("4. Subtract" )
1319
1420while True :
1521 # take input from the user
16- choice = input ("Enter choice(1/2): " )
22+ choice = input ("Enter choice(1/2/3/4 ): " )
1723
18- if choice in ('1' , '2' ):
24+ if choice in ('1' , '2' , '3' , '4' ):
1925 num1 = float (input ("Enter first number: " ))
2026 num2 = float (input ("Enter second number: " ))
2127
@@ -24,9 +30,14 @@ def multiplication(number1, number2):
2430
2531 elif choice == '2' :
2632 print (num1 , "*" , num2 , "=" , multiplication (num1 , num2 ))
33+
34+ elif choice == '3' :
35+ print (num1 , "/" , num2 , "=" , division (num1 , num2 ))
36+
37+ elif choice == '4' :
38+ print (num1 , "-" , num2 , "=" , subtract (num1 , num2 ))
39+
2740
28- # check if user wants another calculation
29- # break the while loop if answer is no
3041 next_calculation = input ("Do you want to do another calculation? (yes/no): " )
3142 if next_calculation == "no" :
3243 break
0 commit comments