-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
32 lines (26 loc) · 1.13 KB
/
example.py
File metadata and controls
32 lines (26 loc) · 1.13 KB
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
"""Example usage of the calculator with plugins."""
from decimal import Decimal
from calculator import Calculator
def main():
"""Demonstrate the calculator with plugin architecture."""
# Create a calculator instance (this will load all plugins)
calc = Calculator()
# Print available operations
print("Available operations:", calc.get_available_operations())
# Perform some calculations using the dynamically loaded operations
print("\nPerforming calculations:")
print(f"2 + 3 = {calc.add(Decimal('2'), Decimal('3'))}")
print(f"5 - 2 = {calc.subtract(Decimal('5'), Decimal('2'))}")
print(f"4 * 6 = {calc.multiply(Decimal('4'), Decimal('6'))}")
print(f"10 / 2 = {calc.divide(Decimal('10'), Decimal('2'))}")
# If the power plugin is available, use it
try:
print(f"2^3 = {calc.power(Decimal('2'), Decimal('3'))}")
except AttributeError:
print("Power operation not available. Add the power.py plugin to enable it.")
# Print the calculation history
print("\nCalculation history:")
for cmd in calc.get_history():
print(f"- {cmd}")
if __name__ == "__main__":
main()