CALCULATOR OF ARSLAN SUKHERA

unknown
plain_text
a year ago
2.2 kB
0
Indexable
Never
```# Define the calculator functions
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 "Cannot divide by zero"
return x / y

def exponentiate(x, y):
return x ** y

def modulus(x, y):
return x % y

# Initialize memory
memory = 0

# Main program loop
while True:
print("Options:")
print("Enter 'subtract' for subtraction")
print("Enter 'multiply' for multiplication")
print("Enter 'divide' for division")
print("Enter 'exponent' for exponentiation")
print("Enter 'modulus' for modulus")
print("Enter 'memory+' to add to memory")
print("Enter 'memory-' to subtract from memory")
print("Enter 'memory recall' to recall memory")
print("Enter 'memory clear' to clear memory")
print("Enter 'quit' to end the program")

# Take user input
user_input = input(": ")

if user_input == "quit":
break
elif user_input in ("add", "subtract", "multiply", "divide", "exponent", "modulus"):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if user_input == "add":
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))
elif user_input == "exponent":
print("Result:", exponentiate(num1, num2))
elif user_input == "modulus":
print("Result:", modulus(num1, num2))
elif user_input == "memory+":
memory += float(input("Enter value to add to memory: "))
elif user_input == "memory-":
memory -= float(input("Enter value to subtract from memory: "))
elif user_input == "memory recall":
print("Memory:", memory)
elif user_input == "memory clear":
memory = 0
else:
print("Invalid input. Please enter a valid option.")```