-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
68 lines (51 loc) · 1.51 KB
/
Copy pathCalculator.py
File metadata and controls
68 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Program to calculate using the arithmetic functions"""
#Function for addition of two numbers
def add(x,y):
return x+y
#Function for substraction of two numbers
def sub(x,y):
return x-y
#Function for multiplication of two numbers
def mul(x,y):
return x*y
#Function for division of two numbers
def div(x,y):
return x/y
#Function for factor of two numbers
def fac(x,y):
return x%y
print ("Select Operation.")
print ("1. Addition")
print ("2. Substraction")
print ("3. Multiplication")
print ("4. Division")
print ("5. Factor")
#Ask user to provide the numbers
a = int(input("Give the first number: "))
b = int(input("Give the second number: "))
#Ask user to provide the option
option = input("Select the operand(1/2/3/4/5):")
#We can add this in the print statement, but for the better output I am assigning a variable to each function
c = add(a,b)
d = sub(a,b)
e = mul(a,b)
f = div(a,b)
g = fac(a,b)
#Using if and elif based on the users option
if option == 1 :
print (a, '+', b, '=', add(a,b))
print ("Addition of {0} and {1} is {2}".format(a,b,c))
elif option == 2:
print (a, "-", b, "=", sub(a,b))
print ("Substraction of {0} and {1} is {2}".format(a,b,d))
elif option == 3:
print (a, "*", b, "=", mul(a,b))
print ("Multiplication of {0} and {1} is {2}".format(a,b,e))
elif option == 4:
print (a, "/", b, "=", div(a,b))
print ("Division of {0} and {1} is {2}".format(a,b,f))
elif option == 5:
print (a, "%", b, "=", fac(a,b))
print ("Factor of {0} and {1} is {2}".format(a,b,g))
else:
print ("Invalid input")