You've learned this already. ✅
Click here to view the next lesson.
Project 1: Basic Calculator
7. Memory Functions
One common feature in many calculators is the ability to store and retrieve a single number from memory. Let's implement this.
memory = None # Initialize memory
# ... previous code ...
print("Enter 'M+' to store the current result into memory")
print("Enter 'MR' to retrieve the number from memory")
print("Enter 'MC' to clear the memory")
# ... within the main loop ...
elif user_input == 'M+':
memory = result # Assuming 'result' is where we store our latest calculated value.
print(f"Saved {result} to memory.")
elif user_input == 'MR':
if memory is None:
print("No value in memory.")
else:
print(f"Retrieved {memory} from memory.")
elif user_input == 'MC':
memory = None
print("Memory cleared.")
# ... rest of the code ...
7. Memory Functions
One common feature in many calculators is the ability to store and retrieve a single number from memory. Let's implement this.
memory = None # Initialize memory
# ... previous code ...
print("Enter 'M+' to store the current result into memory")
print("Enter 'MR' to retrieve the number from memory")
print("Enter 'MC' to clear the memory")
# ... within the main loop ...
elif user_input == 'M+':
memory = result # Assuming 'result' is where we store our latest calculated value.
print(f"Saved {result} to memory.")
elif user_input == 'MR':
if memory is None:
print("No value in memory.")
else:
print(f"Retrieved {memory} from memory.")
elif user_input == 'MC':
memory = None
print("Memory cleared.")
# ... rest of the code ...
7. Memory Functions
One common feature in many calculators is the ability to store and retrieve a single number from memory. Let's implement this.
memory = None # Initialize memory
# ... previous code ...
print("Enter 'M+' to store the current result into memory")
print("Enter 'MR' to retrieve the number from memory")
print("Enter 'MC' to clear the memory")
# ... within the main loop ...
elif user_input == 'M+':
memory = result # Assuming 'result' is where we store our latest calculated value.
print(f"Saved {result} to memory.")
elif user_input == 'MR':
if memory is None:
print("No value in memory.")
else:
print(f"Retrieved {memory} from memory.")
elif user_input == 'MC':
memory = None
print("Memory cleared.")
# ... rest of the code ...
7. Memory Functions
One common feature in many calculators is the ability to store and retrieve a single number from memory. Let's implement this.
memory = None # Initialize memory
# ... previous code ...
print("Enter 'M+' to store the current result into memory")
print("Enter 'MR' to retrieve the number from memory")
print("Enter 'MC' to clear the memory")
# ... within the main loop ...
elif user_input == 'M+':
memory = result # Assuming 'result' is where we store our latest calculated value.
print(f"Saved {result} to memory.")
elif user_input == 'MR':
if memory is None:
print("No value in memory.")
else:
print(f"Retrieved {memory} from memory.")
elif user_input == 'MC':
memory = None
print("Memory cleared.")
# ... rest of the code ...