working socket integration

This commit is contained in:
2025-04-21 21:03:59 +05:30
parent c143efa70e
commit 4453e69e68
22 changed files with 2070 additions and 60 deletions

3
examples/basic_input.py Normal file
View File

@@ -0,0 +1,3 @@
# Very basic input example
name = input("What is your name? ")
print(f"Hello, {name}!")

View 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();

View 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()

View 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();
});
});
});

View 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
View 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}")