Skip to content

Commit c4b6abb

Browse files
committed
Problem 1
2 parents 4f1843e + a1dd390 commit c4b6abb

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

rahulgsalecha/0001/calculator.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#simple calculator
2+
3+
#define functions
4+
5+
def add(x,y):
6+
return x + y
7+
8+
def subtract(x,y):
9+
return x-y
10+
11+
def multiply(x,y):
12+
return x*y
13+
14+
def divide(x,y):
15+
return x/y
16+
17+
#take input from the user
18+
print("Select Operation:")
19+
print("1.Add")
20+
print("2.Subtract")
21+
print("3.Multiply")
22+
print("4.Divide")
23+
24+
choice = int(input("enter choice(1/2/3/4):"))
25+
26+
num1 = int(input("Enter first number: "))
27+
num2 = int(input("Enter second number: "))
28+
29+
if choice == 1:
30+
print(num1,"+",num2,"=", add(num1,num2))
31+
elif choice == 2:
32+
print(num1,"-",num2,"=", subtract(num1,num2))
33+
elif choice == 3:
34+
print(num1,"*",num2,"=", multiply(num1,num2))
35+
elif choice == 4:
36+
print(num1,"/",num2,"=", divide(num1,num2))
37+
else:
38+
print("Invalid input")

rahulgsalecha/0001/result.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
TESTING$ python calculator.py
2+
Select Operation:
3+
1.Add
4+
2.Subtract
5+
3.Multiply
6+
4.Divide
7+
enter choice(1/2/3/4):1
8+
Enter first number: 3
9+
Enter second number: 2
10+
(3, '+', 2, '=', 5)
11+
TESTING$ python calculator.py
12+
Select Operation:
13+
1.Add
14+
2.Subtract
15+
3.Multiply
16+
4.Divide
17+
enter choice(1/2/3/4):2
18+
Enter first number: 2
19+
Enter second number: 3
20+
(2, '-', 3, '=', -1)
21+
TESTING$ python calculator.py
22+
Select Operation:
23+
1.Add
24+
2.Subtract
25+
3.Multiply
26+
4.Divide
27+
enter choice(1/2/3/4):3
28+
Enter first number: 5
29+
Enter second number: 6
30+
(5, '*', 6, '=', 30)
31+
TESTING$ python calculator.py
32+
Select Operation:
33+
1.Add
34+
2.Subtract
35+
3.Multiply
36+
4.Divide
37+
enter choice(1/2/3/4):4
38+
Enter first number: 4
39+
Enter second number: 2
40+
(4, '/', 2, '=', 2)
41+
TESTING$ python calculator.py
42+
Select Operation:
43+
1.Add
44+
2.Subtract
45+
3.Multiply
46+
4.Divide
47+
enter choice(1/2/3/4):1
48+
Enter first number: -1
49+
Enter second number: -1
50+
(-1, '+', -1, '=', -2)
51+
TESTING$ python calculator.py
52+
Select Operation:
53+
1.Add
54+
2.Subtract
55+
3.Multiply
56+
4.Divide
57+
enter choice(1/2/3/4):2
58+
Enter first number: -1
59+
Enter second number: -1
60+
(-1, '-', -1, '=', 0)
61+
TESTING$ python calculator.py
62+
Select Operation:
63+
1.Add
64+
2.Subtract
65+
3.Multiply
66+
4.Divide
67+
enter choice(1/2/3/4):3
68+
Enter first number: 0
69+
Enter second number: 0
70+
(0, '*', 0, '=', 0)
71+
TESTING$ python calculator.py
72+
Select Operation:
73+
1.Add
74+
2.Subtract
75+
3.Multiply
76+
4.Divide
77+
enter choice(1/2/3/4):2
78+
Enter first number: 1
79+
Enter second number: 1
80+
(1, '-', 1, '=', 0)
81+
TESTING$ python calculator.py
82+
Select Operation:
83+
1.Add
84+
2.Subtract
85+
3.Multiply
86+
4.Divide
87+
enter choice(1/2/3/4):4
88+
Enter first number: 0
89+
Enter second number: 0
90+
Traceback (most recent call last):
91+
File "calculator.py", line 36, in <module>
92+
print(num1,"/",num2,"=", divide(num1,num2))
93+
File "calculator.py", line 15, in divide
94+
return x/y
95+
ZeroDivisionError: integer division or modulo by zero
96+
TESTING$

0 commit comments

Comments
 (0)