Skip to content
🤔prompts chat🧠
🔍
question:w would you implement a simple REST API in Node.js that returns the result of basic arithmetic operations? Available operations: addition, subtraction, multiplication, and division.

answer:const express = require('express'); const app = express(); app.use(express.json()); app.post('/calculate', (req, res) => { const { operation, num1, num2 } = req.body; let result; switch (operation) { case 'addition': result = num1 + num2; break; case 'subtraction': result = num1 - num2; break; case 'multiplication': result = num1 * num2; break; case 'division': if (num2 === 0) { return res.status(400).send('Division by zero is not allowed.'); } result = num1 / num2; break; default: res.status(400).send('Invalid operation.'); return; } res.json({ result });}); app.listen(3000, () => { console.log('App is running on port 3000');});

question:Design a Python function that concatenates a list of strings and returns the result. ["hello", "world", "test"]

answer:def concatenate_strings(strings): return ''.join(strings) result = concatenate_strings(["hello", "world", "test"]) print(result)

question:Provide a shell script that counts the number of files and directories in the current directory.

answer:#!/bin/sh file_count=0 dir_count=0 for entry in ./*; do if [ -f "{entry}" ]; then file_count=((file_count + 1)) elif [ -d "{entry}" ]; then dir_count=((dir_count + 1)) fi done echo "Files: {file_count}" echo "Directories: {dir_count}"

question:Write a C++ function that calculates the area of a circle when given its radius. 6.0

answer:#include<iostream> #include<cmath> #define PI 3.14159265 double circle_area(double radius) { return PI * pow(radius, 2);} int main() { double r = 6.0; std::cout << "The area of the circle is: " << circle_area(r) << std::endl; return 0;}

Released under the DeepMind License.

has loaded