Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions scripts/simple_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def add(a, b):
return a + b


def subtract(a, b):
return a - b


def multiply(a, b):
return a * b


def divide(a, b):
if b == 0:
return "Error: Division by zero"
return a / b


if __name__ == "__main__":
print("Simple Calculator")
x = float(input("Enter first number: "))
y = float(input("Enter second number: "))
op = input("Enter operation (+, -, *, /): ")

if op == "+":
print("Result:", add(x, y))
elif op == "-":
print("Result:", subtract(x, y))
elif op == "*":
print("Result:", multiply(x, y))
elif op == "/":
print("Result:", divide(x, y))
else:
print("Invalid operation!")