Dataset Viewer
conversations
listlengths 2
2
| source
stringclasses 4
values |
---|---|
[
{
"from": "human",
"value": "Explain what boolean operators are, what they do, and provide examples of how they can be used."
},
{
"from": "gpt",
"value": "Boolean operators are used to perform logical operations. The main boolean operators are AND, OR, and NOT.\nExample:\n- AND: True and False → False\n- OR: True or False → True\n- NOT: not True → False"
}
]
| Boolean Logic |
[
{
"from": "human",
"value": "Explain how recursion works and provide a recursive function in Python that calculates the factorial of a number."
},
{
"from": "gpt",
"value": "Recursion is a process in which a function calls itself. It's useful for solving problems that can be broken down into similar subproblems.\nExample:\ndef factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)"
}
]
| Recursion |
[
{
"from": "human",
"value": "Explain the concept of recursion with an example, while also implementing a recursive function in Python to calculate Fibonacci numbers."
},
{
"from": "gpt",
"value": "Recursion is when a function calls itself to solve a smaller version of the problem.\nExample:\ndef fibonacci(n):\n if n <= 1:\n return n\n else:\n return fibonacci(n-1) + fibonacci(n-2)"
}
]
| Recursion |
[
{
"from": "human",
"value": "Print the reverse of a string using a for loop."
},
{
"from": "gpt",
"value": "You can reverse a string using a for loop as follows:\ninput_str = 'hello'\nreversed_str = ''\nfor char in input_str:\n reversed_str = char + reversed_str\nprint(reversed_str)"
}
]
| String Manipulation |
[
{
"from": "human",
"value": "How do astronomers determine the original wavelength of light emitted by a celestial body at rest?"
},
{
"from": "gpt",
"value": "Astronomers determine the rest wavelength by measuring the observed wavelength and correcting for the Doppler shift due to motion. This involves using spectroscopy and understanding redshift or blueshift."
}
]
| Astrophysics |
[
{
"from": "human",
"value": "Explain what is meant by recursion in programming. Additionally, write a recursive function to sum the first n natural numbers."
},
{
"from": "gpt",
"value": "Recursion refers to a function calling itself to solve smaller instances of a problem.\nExample:\ndef sum_natural(n):\n if n == 1:\n return 1\n else:\n return n + sum_natural(n-1)"
}
]
| Recursion |
README.md exists but content is empty.
- Downloads last month
- 12