{ "language": "python", "category": "basics", "training_data": [ { "input": "create a hello world program", "output": "print('Hello, World!')\n", "tags": ["beginner", "hello_world", "print"] }, { "input": "write a function to add two numbers", "output": "def add(a, b):\n return a + b\n\nresult = add(5, 3)\nprint(result)\n", "tags": ["functions", "arithmetic"] }, { "input": "create a loop from 1 to 10", "output": "for i in range(1, 11):\n print(i)\n", "tags": ["loops", "range"] }, { "input": "write a list comprehension to get squares", "output": "numbers = [1, 2, 3, 4, 5]\nsquares = [x**2 for x in numbers]\nprint(squares)\n", "tags": ["list_comprehension", "lists"] }, { "input": "create a dictionary with student names and grades", "output": "students = {\n 'Alice': 90,\n 'Bob': 85,\n 'Charlie': 92\n}\nprint(students)\n", "tags": ["dictionary", "data_structures"] }, { "input": "write a function that checks if a number is even", "output": "def is_even(n):\n return n % 2 == 0\n\nprint(is_even(4)) # True\nprint(is_even(7)) # False\n", "tags": ["functions", "conditionals"] }, { "input": "create a class called Person with name and age", "output": "class Person:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n \n def greet(self):\n return f'Hello, I am {self.name}, {self.age} years old'\n\nperson = Person('Alice', 30)\nprint(person.greet())\n", "tags": ["classes", "oop"] }, { "input": "write code to read a file and print its content", "output": "with open('file.txt', 'r') as f:\n content = f.read()\n print(content)\n", "tags": ["file_io", "context_manager"] }, { "input": "create a lambda function to multiply two numbers", "output": "multiply = lambda x, y: x * y\nprint(multiply(5, 3)) # 15\n", "tags": ["lambda", "anonymous_functions"] }, { "input": "write a function with default parameters", "output": "def greet(name, greeting='Hello'):\n return f'{greeting}, {name}!'\n\nprint(greet('Alice')) # Hello, Alice!\nprint(greet('Bob', 'Hi')) # Hi, Bob!\n", "tags": ["functions", "default_parameters"] }, { "input": "create a try except block for error handling", "output": "try:\n result = 10 / 0\nexcept ZeroDivisionError:\n print('Cannot divide by zero')\nfinally:\n print('Operation completed')\n", "tags": ["error_handling", "exceptions"] }, { "input": "write a function to reverse a string", "output": "def reverse_string(s):\n return s[::-1]\n\nprint(reverse_string('hello')) # olleh\n", "tags": ["strings", "slicing"] }, { "input": "create a decorator function", "output": "def my_decorator(func):\n def wrapper():\n print('Before function call')\n func()\n print('After function call')\n return wrapper\n\n@my_decorator\ndef say_hello():\n print('Hello!')\n\nsay_hello()\n", "tags": ["decorators", "higher_order_functions"] }, { "input": "write code to filter even numbers from a list", "output": "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\neven_numbers = list(filter(lambda x: x % 2 == 0, numbers))\nprint(even_numbers)\n", "tags": ["filter", "lambda", "lists"] }, { "input": "create a function to calculate fibonacci sequence", "output": "def fibonacci(n):\n if n <= 0:\n return []\n elif n == 1:\n return [0]\n elif n == 2:\n return [0, 1]\n else:\n fib = [0, 1]\n for i in range(2, n):\n fib.append(fib[i-1] + fib[i-2])\n return fib\n\nprint(fibonacci(10))\n", "tags": ["recursion", "sequences"] } ] }