1
- #first define the functions
2
- #for 2 digits oprations
3
- def add (x , y ):
4
- return x + y
5
- def sub (x ,y ):
6
- return x - y
7
- def mul (x ,y ):
8
- return x * y
9
- def div (x ,y ):
10
- return x / y
11
- def power (x ,y ):
12
- return pow (x , y )
1
+ operation = input ('''
2
+ Please type in the math operation you would like to complete:
3
+ 1 for addition
4
+ 2 for subtraction
5
+ 3 for multiplication
6
+ 4 for division
7
+ ''' )
13
8
14
- #take input from user
15
- print ("Select opration:" )
16
- print ("1.add" )
17
- print ("2.subtract" )
18
- print ("3.multiply" )
19
- print ("4.divide" )
20
- print ("5.power" )
21
- select = input ("Enter any one Choice from 1 to 5 :" )
9
+ num = int (input ('Enter your first number: ' ))
10
+ num2 = int (input ('Enter your second number: ' ))
22
11
23
- num1 = int (input ("Enter the Num1:" ))
24
- num2 = int (input ("Enter the Num2:" ))
12
+ if operation == '1' :
13
+ print ('{} + {} = ' .format (num , num2 ))
14
+ print (num + num2 )
25
15
26
- if select == "1" :
27
- print (num1 ,"+" ,num2 ,"=" , add (num1 ,num2 ))
28
- elif select == "2" :
29
- print (num1 ,"-" ,num2 ,"=" , sub (num1 ,num2 ))
30
- elif select == "3" :
31
- print (num1 ,"x" ,num2 ,"=" , mul (num1 ,num2 ))
32
- elif select == "4" :
33
- print (num1 ,"/" ,num2 ,"=" , div (num1 ,num2 ))
34
- elif select == "2" :
35
- print (num1 ,"*" ,num2 ,"=" , power (num1 ,num2 ))
36
- else :
37
- print ("Not a valid input! tru again" )
16
+ elif operation == '2' :
17
+ print ('{} - {} = ' .format (num , num2 ))
18
+ print (num - num2 )
19
+
20
+ elif operation == '3' :
21
+ print ('{} * {} = ' .format (num , num2 ))
22
+ print (num * num2 )
23
+
24
+ elif operation == '4' :
25
+ print ('{} / {} = ' .format (num , num2 ))
26
+ print (num / num2 )
27
+
28
+ else :
29
+ print ('Wrong Input! Please Try Again' )
0 commit comments