working socket integration
This commit is contained in:
3
examples/basic_input.py
Normal file
3
examples/basic_input.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Very basic input example
|
||||
name = input("What is your name? ")
|
||||
print(f"Hello, {name}!")
|
||||
41
examples/interactive_calculator.js
Normal file
41
examples/interactive_calculator.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// Interactive Calculator Example
|
||||
// This demonstrates how the interactive input/output works
|
||||
|
||||
const readline = require('readline');
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
function calculator() {
|
||||
console.log("Welcome to the Interactive Calculator!");
|
||||
console.log("Enter 'q' to quit at any time.");
|
||||
|
||||
function promptUser() {
|
||||
rl.question("Enter an expression (e.g., 2 + 3): ", (expression) => {
|
||||
if (expression.toLowerCase() === 'q') {
|
||||
console.log("Thank you for using the Interactive Calculator!");
|
||||
rl.close();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Safely evaluate the expression
|
||||
const result = eval(expression);
|
||||
console.log(`Result: ${result}`);
|
||||
} catch (e) {
|
||||
console.log(`Error: ${e.message}`);
|
||||
console.log("Please try again with a valid expression.");
|
||||
}
|
||||
|
||||
// Continue prompting
|
||||
promptUser();
|
||||
});
|
||||
}
|
||||
|
||||
// Start the prompt loop
|
||||
promptUser();
|
||||
}
|
||||
|
||||
// Run the calculator
|
||||
calculator();
|
||||
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()
|
||||
22
examples/interactive_javascript.js
Normal file
22
examples/interactive_javascript.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// Interactive JavaScript Example
|
||||
// This example demonstrates interactive input/output
|
||||
|
||||
const readline = require('readline');
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
rl.question('Enter your name: ', (name) => {
|
||||
console.log(`Hello, ${name}!`);
|
||||
|
||||
rl.question('Enter your age: ', (age) => {
|
||||
console.log(`You are ${age} years old.`);
|
||||
|
||||
rl.question('What is your favorite color? ', (color) => {
|
||||
console.log(`Your favorite color is ${color}.`);
|
||||
console.log('Thank you for using the interactive example!');
|
||||
rl.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
13
examples/interactive_python.py
Normal file
13
examples/interactive_python.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Interactive Python Example
|
||||
# This example demonstrates interactive input/output
|
||||
|
||||
name = input("Enter your name: ")
|
||||
print(f"Hello, {name}!")
|
||||
|
||||
age = input("Enter your age: ")
|
||||
print(f"You are {age} years old.")
|
||||
|
||||
favorite_color = input("What is your favorite color? ")
|
||||
print(f"Your favorite color is {favorite_color}.")
|
||||
|
||||
print("Thank you for using the interactive example!")
|
||||
5
examples/simple_input.py
Normal file
5
examples/simple_input.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Simple input example
|
||||
name = input("Enter your name: ")
|
||||
print(f"Hello, {name}!")
|
||||
for i in range(5):
|
||||
print(f"Count: {i}")
|
||||
Reference in New Issue
Block a user