Skip to content

Commit b8a65c4

Browse files
Merge pull request #274 from souravjain540/revert-81-main
Revert "Improved existing calculator"
2 parents b360a33 + b6e473d commit b8a65c4

File tree

1 file changed

+37
-48
lines changed

1 file changed

+37
-48
lines changed

calculator.py

+37-48
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,59 @@
1-
while True:
2-
# definition for operators
3-
4-
#addition
5-
def add(num1, num2):
6-
return num1+num2
7-
8-
#substraction
9-
def subtract(num1, num2):
10-
return num1-num2
11-
12-
#multiplication
13-
def multiply(num1, num2):
14-
return num1*num2
15-
16-
#division
17-
def divide(num1, num2):
18-
try:
19-
return num1/num2
20-
except ZeroDivisionError:
21-
print ("WARNING: Invalid division, cannot divide by zero")
22-
23-
#exponent
24-
def exponent(num1, num2):
25-
return num1**num2
26-
27-
while True:
28-
try:
29-
num1=float(input("Enter a digit: "))
30-
num2=float(input("Enter another digit: "))
31-
break
32-
except ValueError:
33-
print("The input was not a valid digit")
1+
num1=int(input("eneter a digit"))
2+
num2=int(input("eneter a another digit"))
3+
# defination for operators
4+
5+
#addition
6+
def add(num1, num2):
7+
return num1+num2
8+
#substraction
9+
def subtract(num1, num2):
10+
return num1-num2
11+
#multiply
12+
def multiply(num1, num2):
13+
return num1*num2
14+
#division
15+
def divide(num1, num2):
16+
return num1/num2
17+
18+
#command for operation
19+
print("choose operation")
20+
print("press 1 for add")
21+
print("press 2 for subs")
22+
print("press 3 for multiply")
23+
print("press 4 for devision")
3424

35-
#command for operation
36-
print("Choose an operation")
37-
print("Press 1 for addition")
38-
print("Press 2 for substraction")
39-
print("Press 3 for multiplication")
40-
print("Press 4 for division")
41-
print("Press 5 for exponent")
4225

26+
27+
28+
29+
while True:
4330
# take input from the user
44-
choice = input("Enter choice(1/2/3/4/5): ")
31+
choice = input("Enter choice(1/2/3/4): ")
4532

46-
if choice in ('1', '2', '3', '4', '5'):
33+
if choice in ('1', '2', '3', '4'):
4734

4835
if choice == '1':
4936
print(num1, "+", num2, "=", add(num1, num2))
5037

38+
39+
5140
elif choice == '2':
5241
print(num1, "-", num2, "=", subtract(num1, num2))
5342

5443
elif choice == '3':
5544
print(num1, "*", num2, "=", multiply(num1, num2))
5645

46+
47+
48+
49+
5750
elif choice == '4':
5851
print(num1, "/", num2, "=", divide(num1, num2))
59-
60-
elif choice == '5':
61-
print(num1, "to the power of", num2, "=", exponent(num1, num2))
62-
6352
# check if user wants another calculation
6453
# break the while loop if answer is no
65-
next_calculation = input("Do you want to do another calculation? (yes/no): ")
54+
next_calculation = input("Let's do next calculation? (yes/no): ")
6655
if next_calculation == "no":
6756
break
6857

6958
else:
70-
print("Invalid input")
59+
print("Invalid Input")

0 commit comments

Comments
 (0)