LLMs (Large Language Models) like ChatGPT are great for generating code. Here, we’ll explore some practical examples of how to use ChatGPT for generating useful code.

We’ll use OpenAI’s Playground (Chat Mode) with the gpt-3.5-turbo model for all the examples below.

You can also guide the model’s behavior with a System Message. Here's an example:

You are a helpful code assistant teaching a beginner Python developer. Only generate the code, no explanations.

Basic Example

You can simply provide a direct request to generate code. Here’s an example:

Prompt:
Write Python code that asks for the user's age and tells them how old they will be in 10 years.

ChatGPT generates:

```python
age = int(input("What is your age? "))
future_age = age + 10
print(f"In 10 years, you will be {future_age} years old.")
```

Turning Comments Into Code

You can also turn comments or instructions into code directly. For example:

Prompt:
```python
"""
1. Create a list of 5 fruits.
2. Ask the user for their favorite fruit.
3. Check if the fruit is in the list and print a message accordingly.
"""
```

ChatGPT generates:

```python
fruits = ["apple", "banana", "cherry", "date", "elderberry"]

favorite_fruit = input("What is your favorite fruit? ")

if favorite_fruit.lower() in fruits:
    print(f"{favorite_fruit} is in the list!")
else:
    print(f"Sorry, {favorite_fruit} is not in the list.")
```

Completing Functions

ChatGPT is also capable of completing partially written code. Here’s an example:

Prompt:  
# function to calculate the area of a circle, given the radius
```python
def calculate_area(
```

ChatGPT completes it as follows:

```python
def calculate_area(radius):
    pi = 3.14159
    return pi * radius ** 2
```

MySQL Query Generation

You can also ask ChatGPT to generate useful SQL queries. For example:

Prompt:  
Create a MySQL query to get all employees who earn more than $50,000, from the following table:
```sql
Table employees, columns = [EmployeeId, EmployeeName, Salary]
```

ChatGPT generates:

```sql
SELECT EmployeeId, EmployeeName
FROM employees
WHERE Salary > 50000;
```

You can go further by asking ChatGPT to create a schema for the table:

Prompt:
Create a schema for the `employees` table.

ChatGPT generates:

```sql
CREATE TABLE employees (
  EmployeeId INT PRIMARY KEY,
  EmployeeName VARCHAR(100),
  Salary DECIMAL(10, 2)
);
```

For inserting some sample data:

Prompt:  
Generate valid insert statements for 3 employees.

ChatGPT generates:

```sql
INSERT INTO employees (EmployeeId, EmployeeName, Salary)
VALUES (1, 'John Smith', 55000), (2, 'Jane Doe', 48000), (3, 'Alice Johnson', 75000);
```

Asking for Code Explanations

You can also ask ChatGPT to explain code. Let’s try with this Python example:

Prompt:
Explain the following Python code: 
```python
numbers = [2, 4, 6, 8, 10]
squared_numbers = [n ** 2 for n in numbers]
print(squared_numbers)
```

ChatGPT might explain it like this:

This code takes a list of numbers and creates a new list called `squared_numbers` where each number from the original list is squared (multiplied by itself). The result is printed, which would be: `[4, 16, 36, 64, 100]`.

By using ChatGPT in these ways, you can generate, modify, or understand code more easily!