working socket integration
This commit is contained in:
24
examples/interactive_calculator.py
Normal file
24
examples/interactive_calculator.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Interactive Calculator Example
|
||||
# This demonstrates how the interactive input/output works
|
||||
|
||||
def calculator():
|
||||
print("Welcome to the Interactive Calculator!")
|
||||
print("Enter 'q' to quit at any time.")
|
||||
|
||||
while True:
|
||||
expression = input("Enter an expression (e.g., 2 + 3): ")
|
||||
|
||||
if expression.lower() == 'q':
|
||||
print("Thank you for using the Interactive Calculator!")
|
||||
break
|
||||
|
||||
try:
|
||||
# Safely evaluate the expression
|
||||
result = eval(expression)
|
||||
print(f"Result: {result}")
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
print("Please try again with a valid expression.")
|
||||
|
||||
# Run the calculator
|
||||
calculator()
|
||||
Reference in New Issue
Block a user