forked from tecky708/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcultor.py
42 lines (34 loc) · 1.11 KB
/
calcultor.py
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
# Simple Calculator App in Python
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Error: Division by zero"
return x / y
while True:
print("Options:")
print("Enter 'add' for addition")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input in ["add", "subtract", "multiply", "divide"]:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if user_input == "add":
print("Result:", add(num1, num2))
elif user_input == "subtract":
print("Result:", subtract(num1, num2))
elif user_input == "multiply":
print("Result:", multiply(num1, num2))
elif user_input == "divide":
print("Result:", divide(num1, num2))
else:
print("Invalid input. Please try again.")