Skip to content

Commit 7d46ab2

Browse files
committed
Added simple calculator script
1 parent c79034c commit 7d46ab2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

scripts/simple_calculator.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def add(a, b):
2+
return a + b
3+
4+
def subtract(a, b):
5+
return a - b
6+
7+
def multiply(a, b):
8+
return a * b
9+
10+
def divide(a, b):
11+
if b == 0:
12+
return "Error: Division by zero"
13+
return a / b
14+
15+
if __name__ == "__main__":
16+
print("Simple Calculator")
17+
x = float(input("Enter first number: "))
18+
y = float(input("Enter second number: "))
19+
op = input("Enter operation (+, -, *, /): ")
20+
21+
if op == '+':
22+
print("Result:", add(x, y))
23+
elif op == '-':
24+
print("Result:", subtract(x, y))
25+
elif op == '*':
26+
print("Result:", multiply(x, y))
27+
elif op == '/':
28+
print("Result:", divide(x, y))
29+
else:
30+
print("Invalid operation!")
31+
32+
33+

0 commit comments

Comments
 (0)