-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
99 lines (68 loc) · 2.12 KB
/
Copy pathcalculator.py
File metadata and controls
99 lines (68 loc) · 2.12 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#welcome to Rahul's calculator
#function to add
def addition(a,b):
return a+b
#function for subtraction
def subtraction(a,b):
return a-b
#function for multiplication
def multiplication(a,b):
return a*b
#function for division
def division(a,b):
if(b==0):
print("you can't take divisior 0 : ")
exit()
return a/b
#function for modulo
def modulo(a,b):
if(b==0):
print("you can't take divisior 0 : ")
exit()
return a%b
print("In which type do you want to take number ")
print("""1. Int 2. Float""")
type = (input("Enter your choice 1 or 2 : "))
if type=="1":
num1 = int(input("Enter the first number : "))
num2 = int(input("Enter the second number : "))
if type=="2":
num1 = float(input("Enter the first number : "))
num2 = float(input("Enter the second number : "))
else:
print("Invalid input please type 1 or 2 ")
type = (input(""))
if type=="1":
num1 = int(input("Enter the first number : "))
num2 = int(input("Enter the second number : "))
if type=="2":
num1 = float(input("Enter the first number : "))
num2 = float(input("Enter the second number : "))
print("which operation d2o you want to perform : ")
print("""chose operator :
1. Addition
2. Subtraction
3. Division
4. Multiplication
5. Modulo""")
print("""Enter + for Addition
- for Subtraction
/ for division
* for multiplication
% for modulo""")
optr = (input())
if optr == "+":
result = addition(num1,num2)
print("Result : a+b = ",result)
if optr == "-":
result = subtraction(num1,num2)
print("Result : a-b = ",result)
if optr == "/":
result = division(num1,num2)
print("Result : a/b = ",result)
if optr == "*":
result = multiplication(num1,num2)
print("Result : a*b = ",result)
if optr == "%":
result = modulo(num1,num2)
print("Result : a%b = ",result)