problem_id
stringlengths 9
11
| conversation
listlengths 1
1
| prompt_raw
stringlengths 884
2.13k
| prompt_text
stringlengths 1.01k
2.26k
| response
stringlengths 495
2.28k
|
---|---|---|---|---|
program_77
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_77_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'quantity'. The task is to prompt the user to input an item type and then execute an SQL query to retrieve and print all records from the 'inventory' table where the 'item_type' matches the user's input. The input should be a single string representing the item type to search for in the database.\n\n[Example Input & Output]\n- Input: Accessory\\n ; Output: (3, 'Screwdriver', 'Accessory', 100)\\n(7, 'Tape Measure', 'Accessory', 60)\n- Input: Tool\\n ; Output: (1, 'Hammer', 'Tool', 50)\\n(2, 'Drill', 'Tool', 30)\\n(4, 'Wrench', 'Tool', 40)\\n(5, 'Pliers', 'Tool', 25)\\n(6, 'Saw', 'Tool', 15)\\n(8, 'Level', 'Tool', 20)\\n(9, 'Chisel', 'Tool', 45)\\n(10, 'Utility Knife', 'Tool', 35)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_77_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'quantity'. The task is to prompt the user to input an item type and then execute an SQL query to retrieve and print all records from the 'inventory' table where the 'item_type' matches the user's input. The input should be a single string representing the item type to search for in the database.
[Example Input & Output]
- Input: Accessory\n ; Output: (3, 'Screwdriver', 'Accessory', 100)\n(7, 'Tape Measure', 'Accessory', 60)
- Input: Tool\n ; Output: (1, 'Hammer', 'Tool', 50)\n(2, 'Drill', 'Tool', 30)\n(4, 'Wrench', 'Tool', 40)\n(5, 'Pliers', 'Tool', 25)\n(6, 'Saw', 'Tool', 15)\n(8, 'Level', 'Tool', 20)\n(9, 'Chisel', 'Tool', 45)\n(10, 'Utility Knife', 'Tool', 35)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_77_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'quantity'. The task is to prompt the user to input an item type and then execute an SQL query to retrieve and print all records from the 'inventory' table where the 'item_type' matches the user's input. The input should be a single string representing the item type to search for in the database.
[Example Input & Output]
- Input: Accessory\n ; Output: (3, 'Screwdriver', 'Accessory', 100)\n(7, 'Tape Measure', 'Accessory', 60)
- Input: Tool\n ; Output: (1, 'Hammer', 'Tool', 50)\n(2, 'Drill', 'Tool', 30)\n(4, 'Wrench', 'Tool', 40)\n(5, 'Pliers', 'Tool', 25)\n(6, 'Saw', 'Tool', 15)\n(8, 'Level', 'Tool', 20)\n(9, 'Chisel', 'Tool', 45)\n(10, 'Utility Knife', 'Tool', 35)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_77_database.db')
# Prompt the user to input an item type to search for
item_type = input("Enter the item type to search for: ")
# Construct and execute the SQL query
cursor = conn.cursor()
query = "SELECT * FROM inventory WHERE item_type = ?"
cursor.execute(query, (item_type,))
# Fetch all the records
records = cursor.fetchall()
# Print all the records
for record in records:
print(record)
# Close the database connection
conn.close()
|
program_60
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_60_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id' (INTEGER), 'title' (TEXT), 'author' (TEXT), 'price' (REAL), and 'genre' (TEXT). The task is to prompt the user for three inputs: a minimum price, a maximum price, and a genre. Use these inputs to filter the books based on the adjusted price range and the specified genre. The adjusted minimum price should be 90% of the user-provided minimum, and the adjusted maximum price should be 110% of the user-provided maximum. Retrieve and print the details of books that fall within this adjusted price range and match the specified genre.\n\n[Example Input & Output]\n- Input: 6\\n12\\nRomance\\n ; Output: Title: Pride and Prejudice, Author: Jane Austen, Price: 9.99, Genre: Romance\n- Input: 13\\n18\\nAdventure\\n ; Output: Title: Moby Dick, Author: Herman Melville, Price: 11.99, Genre: Adventure\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_60_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id' (INTEGER), 'title' (TEXT), 'author' (TEXT), 'price' (REAL), and 'genre' (TEXT). The task is to prompt the user for three inputs: a minimum price, a maximum price, and a genre. Use these inputs to filter the books based on the adjusted price range and the specified genre. The adjusted minimum price should be 90% of the user-provided minimum, and the adjusted maximum price should be 110% of the user-provided maximum. Retrieve and print the details of books that fall within this adjusted price range and match the specified genre.
[Example Input & Output]
- Input: 6\n12\nRomance\n ; Output: Title: Pride and Prejudice, Author: Jane Austen, Price: 9.99, Genre: Romance
- Input: 13\n18\nAdventure\n ; Output: Title: Moby Dick, Author: Herman Melville, Price: 11.99, Genre: Adventure
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_60_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id' (INTEGER), 'title' (TEXT), 'author' (TEXT), 'price' (REAL), and 'genre' (TEXT). The task is to prompt the user for three inputs: a minimum price, a maximum price, and a genre. Use these inputs to filter the books based on the adjusted price range and the specified genre. The adjusted minimum price should be 90% of the user-provided minimum, and the adjusted maximum price should be 110% of the user-provided maximum. Retrieve and print the details of books that fall within this adjusted price range and match the specified genre.
[Example Input & Output]
- Input: 6\n12\nRomance\n ; Output: Title: Pride and Prejudice, Author: Jane Austen, Price: 9.99, Genre: Romance
- Input: 13\n18\nAdventure\n ; Output: Title: Moby Dick, Author: Herman Melville, Price: 11.99, Genre: Adventure
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_60_database.db')
cursor = conn.cursor()
# Prompt the user to enter a minimum price, maximum price, and genre
min_price = float(input("Enter minimum price: "))
max_price = float(input("Enter maximum price: "))
genre = input("Enter genre: ")
# Adjust the price range
adjusted_min_price = min_price * 0.9
adjusted_max_price = max_price * 1.1
# Construct the SQL query
query = """
SELECT title, author, price, genre
FROM books
WHERE price BETWEEN ? AND ?
AND genre = ?
"""
# Execute the query
cursor.execute(query, (adjusted_min_price, adjusted_max_price, genre))
# Fetch all results
results = cursor.fetchall()
# Print the title, author, price, and genre for each result
for row in results:
print(f"Title: {row[0]}, Author: {row[1]}, Price: {row[2]}, Genre: {row[3]}")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_225
|
[
{
"content": "[Problem]\nWe have a database file named 'program_225_database.db' which contains a table called 'users'. This table has the following columns: 'user_id', 'username', 'email', and 'bio'. The task is to write a Python script that connects to this database and allows a user to search for entries in the 'users' table. The user should be able to input a search term and specify whether they want to search by 'username' or 'email'. Based on the user's input, the script should query the database for records where the specified column contains the search term and print out the results. The script should handle two inputs: the search term and the filter type ('username' or 'email').\n\n[Example Input & Output]\n- Input: @example.com\\nemail\\n ; Output: (1, 'john_doe', '[email protected]', 'Just a regular Joe.')\\n(2, 'jane_smith', '[email protected]', 'Aspiring author. Coffee enthusiast.')\\n(3, 'admin', '[email protected]', 'System administrator.')\\n(4, 'alice_jones', '[email protected]', 'Nature lover and photographer.')\\n(5, 'bob_brown', '[email protected]', 'Tech geek and gamer.')\\n(6, 'charlie_black', '[email protected]', 'Musician and artist.')\\n(7, 'diana_white', '[email protected]', 'Traveler and food blogger.')\\n(8, 'eve_green', '[email protected]', 'Fitness coach and nutritionist.')\\n(9, 'frank_red', '[email protected]', 'Entrepreneur and investor.')\n- Input: charlie\\nusername\\n ; Output: (6, 'charlie_black', '[email protected]', 'Musician and artist.')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_225_database.db' which contains a table called 'users'. This table has the following columns: 'user_id', 'username', 'email', and 'bio'. The task is to write a Python script that connects to this database and allows a user to search for entries in the 'users' table. The user should be able to input a search term and specify whether they want to search by 'username' or 'email'. Based on the user's input, the script should query the database for records where the specified column contains the search term and print out the results. The script should handle two inputs: the search term and the filter type ('username' or 'email').
[Example Input & Output]
- Input: @example.com\nemail\n ; Output: (1, 'john_doe', '[email protected]', 'Just a regular Joe.')\n(2, 'jane_smith', '[email protected]', 'Aspiring author. Coffee enthusiast.')\n(3, 'admin', '[email protected]', 'System administrator.')\n(4, 'alice_jones', '[email protected]', 'Nature lover and photographer.')\n(5, 'bob_brown', '[email protected]', 'Tech geek and gamer.')\n(6, 'charlie_black', '[email protected]', 'Musician and artist.')\n(7, 'diana_white', '[email protected]', 'Traveler and food blogger.')\n(8, 'eve_green', '[email protected]', 'Fitness coach and nutritionist.')\n(9, 'frank_red', '[email protected]', 'Entrepreneur and investor.')
- Input: charlie\nusername\n ; Output: (6, 'charlie_black', '[email protected]', 'Musician and artist.')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_225_database.db' which contains a table called 'users'. This table has the following columns: 'user_id', 'username', 'email', and 'bio'. The task is to write a Python script that connects to this database and allows a user to search for entries in the 'users' table. The user should be able to input a search term and specify whether they want to search by 'username' or 'email'. Based on the user's input, the script should query the database for records where the specified column contains the search term and print out the results. The script should handle two inputs: the search term and the filter type ('username' or 'email').
[Example Input & Output]
- Input: @example.com\nemail\n ; Output: (1, 'john_doe', '[email protected]', 'Just a regular Joe.')\n(2, 'jane_smith', '[email protected]', 'Aspiring author. Coffee enthusiast.')\n(3, 'admin', '[email protected]', 'System administrator.')\n(4, 'alice_jones', '[email protected]', 'Nature lover and photographer.')\n(5, 'bob_brown', '[email protected]', 'Tech geek and gamer.')\n(6, 'charlie_black', '[email protected]', 'Musician and artist.')\n(7, 'diana_white', '[email protected]', 'Traveler and food blogger.')\n(8, 'eve_green', '[email protected]', 'Fitness coach and nutritionist.')\n(9, 'frank_red', '[email protected]', 'Entrepreneur and investor.')
- Input: charlie\nusername\n ; Output: (6, 'charlie_black', '[email protected]', 'Musician and artist.')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from getpass import getpass
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_225_database.db')
cursor = conn.cursor()
# Prompt the user for a search term and filter type
search_term = input("Enter search term: ")
filter_type = input("Enter filter type (username/email): ").strip().lower()
# Validate the filter type
if filter_type not in ['username', 'email']:
print("Invalid filter type. Please enter 'username' or 'email'.")
return
# Construct and execute the parameterized SQL query
if filter_type == 'username':
query = "SELECT * FROM users WHERE username LIKE ?"
else:
query = "SELECT * FROM users WHERE email LIKE ?"
cursor.execute(query, ('%' + search_term + '%',))
# Fetch and print the results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No results found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_277
|
[
{
"content": "[Problem]\nWe have a database file named 'program_277_database.db' which contains a table called 'tickets'. This table has the following columns: 'id' (an integer primary key), 'event_name' (a text field), 'date' (a text field representing the date), 'price' (a real number representing the price), and 'location' (a text field). The task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user should provide four inputs: the name of the event (or 'all' to match any event), a start date, an end date, and a location. The code should query the 'tickets' table to find all records where the event name matches the input (or any event if 'all' is specified), the date is between the start and end dates provided, and the location matches the input. Finally, the code should print the results of this query.\n\n[Example Input & Output]\n- Input: Festival A\\n2023-12-25\\n2023-12-31\\nDenver\\n ; Output: []\n- Input: Theatre Z\\n2023-12-01\\n2023-12-31\\nPhiladelphia\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_277_database.db' which contains a table called 'tickets'. This table has the following columns: 'id' (an integer primary key), 'event_name' (a text field), 'date' (a text field representing the date), 'price' (a real number representing the price), and 'location' (a text field). The task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user should provide four inputs: the name of the event (or 'all' to match any event), a start date, an end date, and a location. The code should query the 'tickets' table to find all records where the event name matches the input (or any event if 'all' is specified), the date is between the start and end dates provided, and the location matches the input. Finally, the code should print the results of this query.
[Example Input & Output]
- Input: Festival A\n2023-12-25\n2023-12-31\nDenver\n ; Output: []
- Input: Theatre Z\n2023-12-01\n2023-12-31\nPhiladelphia\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_277_database.db' which contains a table called 'tickets'. This table has the following columns: 'id' (an integer primary key), 'event_name' (a text field), 'date' (a text field representing the date), 'price' (a real number representing the price), and 'location' (a text field). The task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user should provide four inputs: the name of the event (or 'all' to match any event), a start date, an end date, and a location. The code should query the 'tickets' table to find all records where the event name matches the input (or any event if 'all' is specified), the date is between the start and end dates provided, and the location matches the input. Finally, the code should print the results of this query.
[Example Input & Output]
- Input: Festival A\n2023-12-25\n2023-12-31\nDenver\n ; Output: []
- Input: Theatre Z\n2023-12-01\n2023-12-31\nPhiladelphia\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_tickets(event_name, start_date, end_date, location):
# Connect to the SQLite database
conn = sqlite3.connect('program_277_database.db')
cursor = conn.cursor()
# Construct the SQL query
query = """
SELECT *
FROM tickets
WHERE event_name = ? AND start_date BETWEEN ? AND ? AND location = ?
"""
# Execute the query
cursor.execute(query, (event_name, start_date, end_date, location))
# Fetch all the tickets
tickets = cursor.fetchall()
# Close the connection
conn.close()
return tickets
# Main function to prompt user inputs and display tickets
if __name__ == "__main__":
# Prompt user for inputs
event_name = input("Enter the event name: ")
start_date = input("Enter the start date (YYYY-MM-DD): ")
end_date = input("Enter the end date (YYYY-MM-DD): ")
location = input("Enter the location: ")
# Call the get_tickets function
tickets = get_tickets(event_name, start_date, end_date, location)
# Print the retrieved tickets
if tickets:
for ticket in tickets:
print(ticket)
else:
print("No tickets found.")
|
program_356
|
[
{
"content": "[Problem]\nThe database is named 'program_356_database.db' and contains a table called 'census_data'. This table has the following columns: 'citizen_id', 'full_name', 'age', 'city', 'income', and 'employment_status'. The task is to write a script that connects to this database and retrieves records from the 'census_data' table based on certain conditions. Specifically, the script should take four inputs: a minimum income threshold, an age, an employment status, and an adjustment factor. The script should then adjust the minimum income by adding the adjustment factor to it and use this adjusted value to filter records where the income is greater than or equal to this adjusted value, or where the age matches the input age, or where the employment status matches the input employment status. The script should execute this query and print out the results.\n\n[Example Input & Output]\n- Input: 62000\\n32\\nEmployed\\n8000\\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')\n- Input: 30000\\n30\\nEmployed\\n10000\\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\\n(2, 'Jane Smith', 29, 'Gotham', 62000.0, 'Self-Employed')\\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_356_database.db' and contains a table called 'census_data'. This table has the following columns: 'citizen_id', 'full_name', 'age', 'city', 'income', and 'employment_status'. The task is to write a script that connects to this database and retrieves records from the 'census_data' table based on certain conditions. Specifically, the script should take four inputs: a minimum income threshold, an age, an employment status, and an adjustment factor. The script should then adjust the minimum income by adding the adjustment factor to it and use this adjusted value to filter records where the income is greater than or equal to this adjusted value, or where the age matches the input age, or where the employment status matches the input employment status. The script should execute this query and print out the results.
[Example Input & Output]
- Input: 62000\n32\nEmployed\n8000\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')
- Input: 30000\n30\nEmployed\n10000\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\n(2, 'Jane Smith', 29, 'Gotham', 62000.0, 'Self-Employed')\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_356_database.db' and contains a table called 'census_data'. This table has the following columns: 'citizen_id', 'full_name', 'age', 'city', 'income', and 'employment_status'. The task is to write a script that connects to this database and retrieves records from the 'census_data' table based on certain conditions. Specifically, the script should take four inputs: a minimum income threshold, an age, an employment status, and an adjustment factor. The script should then adjust the minimum income by adding the adjustment factor to it and use this adjusted value to filter records where the income is greater than or equal to this adjusted value, or where the age matches the input age, or where the employment status matches the input employment status. The script should execute this query and print out the results.
[Example Input & Output]
- Input: 62000\n32\nEmployed\n8000\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')
- Input: 30000\n30\nEmployed\n10000\n ; Output: (1, 'John Doe', 34, 'Metropolis', 55000.0, 'Employed')\n(2, 'Jane Smith', 29, 'Gotham', 62000.0, 'Self-Employed')\n(3, 'Emily Clark', 42, 'Star City', 75000.0, 'Unemployed')\n(4, 'Michael Johnson', 58, 'Central City', 88000.0, 'Retired')\n(5, 'Sarah Connor', 35, 'Los Angeles', 68000.0, 'Employed')\n(6, 'Bruce Wayne', 45, 'Gotham', 150000.0, 'Self-Employed')\n(7, 'Clark Kent', 30, 'Metropolis', 75000.0, 'Employed')\n(9, 'Peter Parker', 21, 'New York', 30000.0, 'Employed')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def fetch_census_data(min_income, age, employment_status, adjustment_factor):
# Establish a connection to the SQLite database
conn = sqlite3.connect('program_356_database.db')
cursor = conn.cursor()
# Adjust the minimum income by adding the adjustment factor
adjusted_min_income = min_income + adjustment_factor
# Construct the SQL query
query = """
SELECT * FROM census_data
WHERE income >= ? AND age >= ? AND employment_status = ?
"""
# Execute the query
cursor.execute(query, (adjusted_min_income, age, employment_status))
# Fetch all results
results = cursor.fetchall()
# Print each result
for result in results:
print(result)
# Close the database connection
conn.close()
if __name__ == "__main__":
# Prompt the user for input
min_income = float(input("Enter the minimum income threshold: "))
age = int(input("Enter the minimum age: "))
employment_status = input("Enter the employment status: ")
adjustment_factor = float(input("Enter the adjustment factor for the minimum income: "))
# Call the fetch_census_data function with user inputs
fetch_census_data(min_income, age, employment_status, adjustment_factor)
|
program_149
|
[
{
"content": "[Problem]\nThe database is stored in a file named 'program_149_database.db' and contains a table called 'items'. This table has four columns: 'id' (INTEGER), 'description' (TEXT), 'type' (TEXT), and 'price' (REAL). The task is to write a script that connects to this database and allows a user to input an item id and a description. The script should then query the 'items' table to find and print all records where the 'id' matches the input or the 'description' contains the input. The script should prompt the user for two inputs: the item id and the description. Use these inputs to construct and execute a SQL query that retrieves the relevant records from the database.\n\n[Example Input & Output]\n- Input: 6\\nLaptop\\n ; Output: (6, 'Laptop', 'Electronics', 999.99)\n- Input: 4\\nLamp\\n ; Output: (4, 'Lamp', 'Furniture', 34.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is stored in a file named 'program_149_database.db' and contains a table called 'items'. This table has four columns: 'id' (INTEGER), 'description' (TEXT), 'type' (TEXT), and 'price' (REAL). The task is to write a script that connects to this database and allows a user to input an item id and a description. The script should then query the 'items' table to find and print all records where the 'id' matches the input or the 'description' contains the input. The script should prompt the user for two inputs: the item id and the description. Use these inputs to construct and execute a SQL query that retrieves the relevant records from the database.
[Example Input & Output]
- Input: 6\nLaptop\n ; Output: (6, 'Laptop', 'Electronics', 999.99)
- Input: 4\nLamp\n ; Output: (4, 'Lamp', 'Furniture', 34.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is stored in a file named 'program_149_database.db' and contains a table called 'items'. This table has four columns: 'id' (INTEGER), 'description' (TEXT), 'type' (TEXT), and 'price' (REAL). The task is to write a script that connects to this database and allows a user to input an item id and a description. The script should then query the 'items' table to find and print all records where the 'id' matches the input or the 'description' contains the input. The script should prompt the user for two inputs: the item id and the description. Use these inputs to construct and execute a SQL query that retrieves the relevant records from the database.
[Example Input & Output]
- Input: 6\nLaptop\n ; Output: (6, 'Laptop', 'Electronics', 999.99)
- Input: 4\nLamp\n ; Output: (4, 'Lamp', 'Furniture', 34.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_149_database.db')
cursor = conn.cursor()
# Prompt the user for input
item_id = input("Enter item ID: ")
item_description = input("Enter item description: ")
# Construct the SQL query with parameterized query to prevent SQL injection
query = "SELECT * FROM items WHERE item_id = ? AND item_description = ?"
cursor.execute(query, (item_id, item_description))
# Fetch the results
results = cursor.fetchall()
# Print the results
for row in results:
print(row)
# Close the database connection
conn.close()
|
program_407
|
[
{
"content": "[Problem]\nYou have a database file named 'program_407_database.db' which contains a table called 'tickets'. This table has the following columns: 'ticket_id' (INTEGER), 'event_name' (TEXT), 'date' (TEXT), and 'price' (REAL). Your task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user will provide four inputs: a minimum ticket price, a maximum ticket price, an event date in the format 'YYYY-MM-DD', and a part of the event name. The code should construct an SQL query to select all records from the 'tickets' table where the price is between the given minimum and maximum, the date matches the provided event date, and the event name contains the provided substring. Finally, execute this query and print the results.\n\n[Example Input & Output]\n- Input: 30\\n70\\n2023-12-06\\nShow\\n ; Output: [(6, 'Comedy Show', '2023-12-06', 40.0)]\n- Input: 70\\n120\\n2023-12-10\\nFestival\\n ; Output: [(10, 'Festival', '2023-12-10', 90.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_407_database.db' which contains a table called 'tickets'. This table has the following columns: 'ticket_id' (INTEGER), 'event_name' (TEXT), 'date' (TEXT), and 'price' (REAL). Your task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user will provide four inputs: a minimum ticket price, a maximum ticket price, an event date in the format 'YYYY-MM-DD', and a part of the event name. The code should construct an SQL query to select all records from the 'tickets' table where the price is between the given minimum and maximum, the date matches the provided event date, and the event name contains the provided substring. Finally, execute this query and print the results.
[Example Input & Output]
- Input: 30\n70\n2023-12-06\nShow\n ; Output: [(6, 'Comedy Show', '2023-12-06', 40.0)]
- Input: 70\n120\n2023-12-10\nFestival\n ; Output: [(10, 'Festival', '2023-12-10', 90.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_407_database.db' which contains a table called 'tickets'. This table has the following columns: 'ticket_id' (INTEGER), 'event_name' (TEXT), 'date' (TEXT), and 'price' (REAL). Your task is to write a code snippet that connects to this database and retrieves records from the 'tickets' table based on user inputs. The user will provide four inputs: a minimum ticket price, a maximum ticket price, an event date in the format 'YYYY-MM-DD', and a part of the event name. The code should construct an SQL query to select all records from the 'tickets' table where the price is between the given minimum and maximum, the date matches the provided event date, and the event name contains the provided substring. Finally, execute this query and print the results.
[Example Input & Output]
- Input: 30\n70\n2023-12-06\nShow\n ; Output: [(6, 'Comedy Show', '2023-12-06', 40.0)]
- Input: 70\n120\n2023-12-10\nFestival\n ; Output: [(10, 'Festival', '2023-12-10', 90.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_407_database.db')
cursor = conn.cursor()
# Prompt the user for input
min_price = float(input("Enter the minimum ticket price: "))
max_price = float(input("Enter the maximum ticket price: "))
event_date_input = input("Enter the event date (YYYY-MM-DD): ")
event_name_part = input("Enter the part of the event name: ")
# Validate event date input
try:
event_date = datetime.strptime(event_date_input, "%Y-%m-%d").date()
except ValueError:
print("Invalid date format. Please use YYYY-MM-DD.")
return
# Construct and execute the SQL query
query = """
SELECT ticket_id, event_name, date, price
FROM tickets
WHERE price BETWEEN ? AND ?
AND date = ?
AND event_name LIKE ?
"""
cursor.execute(query, (min_price, max_price, event_date, f"%{event_name_part}%"))
# Fetch and print all results
results = cursor.fetchall()
if results:
print("Ticket ID\tEvent Name\tDate\tPrice")
for row in results:
print(f"{row[0]}\t{row[1]}\t{row[2]}\t{row[3]}")
else:
print("No matching tickets found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_195
|
[
{
"content": "[Problem]\nYou have a database file named 'program_195_database.db' with a table called 'posts'. This table contains columns: post_id, title, content, author, and publish_date. Your task is to write a code snippet that retrieves and prints posts from this table based on user input. The user will provide four inputs: an author's name, a start publish date, an end publish date, and a keyword. The code should query the database to find posts where the author matches the given name, the publish date is between the start and end dates, and the keyword is contained in either the title or the content of the post. The results should be printed to the console.\n\n[Example Input & Output]\n- Input: Charlie\\n2023-04-01\\n2023-08-01\\nInsights\\n ; Output: (7, 'Seventh Post', 'Insights from a blogger.', 'Charlie', '2023-07-22')\n- Input: Alice\\n2023-01-01\\n2023-05-31\\nfirst\\n ; Output: (1, 'First Post', 'This is the first blog post.', 'Alice', '2023-01-01')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_195_database.db' with a table called 'posts'. This table contains columns: post_id, title, content, author, and publish_date. Your task is to write a code snippet that retrieves and prints posts from this table based on user input. The user will provide four inputs: an author's name, a start publish date, an end publish date, and a keyword. The code should query the database to find posts where the author matches the given name, the publish date is between the start and end dates, and the keyword is contained in either the title or the content of the post. The results should be printed to the console.
[Example Input & Output]
- Input: Charlie\n2023-04-01\n2023-08-01\nInsights\n ; Output: (7, 'Seventh Post', 'Insights from a blogger.', 'Charlie', '2023-07-22')
- Input: Alice\n2023-01-01\n2023-05-31\nfirst\n ; Output: (1, 'First Post', 'This is the first blog post.', 'Alice', '2023-01-01')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_195_database.db' with a table called 'posts'. This table contains columns: post_id, title, content, author, and publish_date. Your task is to write a code snippet that retrieves and prints posts from this table based on user input. The user will provide four inputs: an author's name, a start publish date, an end publish date, and a keyword. The code should query the database to find posts where the author matches the given name, the publish date is between the start and end dates, and the keyword is contained in either the title or the content of the post. The results should be printed to the console.
[Example Input & Output]
- Input: Charlie\n2023-04-01\n2023-08-01\nInsights\n ; Output: (7, 'Seventh Post', 'Insights from a blogger.', 'Charlie', '2023-07-22')
- Input: Alice\n2023-01-01\n2023-05-31\nfirst\n ; Output: (1, 'First Post', 'This is the first blog post.', 'Alice', '2023-01-01')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_195_database.db')
cursor = conn.cursor()
# Prompt the user for input
author = input("Enter the author's name: ")
start_date = input("Enter the start publish date (YYYY-MM-DD): ")
end_date = input("Enter the end publish date (YYYY-MM-DD): ")
keyword = input("Enter the keyword: ")
# Execute the SQL query
query = """
SELECT post_id, title, content, author, publish_date
FROM posts
WHERE author = ? AND publish_date BETWEEN ? AND ?
AND (title LIKE ? OR content LIKE ?)
"""
cursor.execute(query, (author, start_date, end_date, f'%{keyword}%', f'%{keyword}%'))
# Fetch and print all results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_185
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_185_database.db' and queries a table called 'events'. The 'events' table contains columns: event_id, title, date, location, and available_tickets. The task is to prompt the user for three inputs: a location (string), an event date (string), and a ticket amount (integer). Use these inputs to construct and execute a SQL query that selects all events from the 'events' table where the location matches the user input, the date matches the user input, and the available tickets are greater than or equal to the ticket amount specified by the user. Finally, print the results of the query.\n\n[Example Input & Output]\n- Input: Theater\\n2023-11-25\\n20\\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)\n- Input: Theater\\n2023-11-25\\n10\\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_185_database.db' and queries a table called 'events'. The 'events' table contains columns: event_id, title, date, location, and available_tickets. The task is to prompt the user for three inputs: a location (string), an event date (string), and a ticket amount (integer). Use these inputs to construct and execute a SQL query that selects all events from the 'events' table where the location matches the user input, the date matches the user input, and the available tickets are greater than or equal to the ticket amount specified by the user. Finally, print the results of the query.
[Example Input & Output]
- Input: Theater\n2023-11-25\n20\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)
- Input: Theater\n2023-11-25\n10\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_185_database.db' and queries a table called 'events'. The 'events' table contains columns: event_id, title, date, location, and available_tickets. The task is to prompt the user for three inputs: a location (string), an event date (string), and a ticket amount (integer). Use these inputs to construct and execute a SQL query that selects all events from the 'events' table where the location matches the user input, the date matches the user input, and the available tickets are greater than or equal to the ticket amount specified by the user. Finally, print the results of the query.
[Example Input & Output]
- Input: Theater\n2023-11-25\n20\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)
- Input: Theater\n2023-11-25\n10\n ; Output: (3, 'Play', '2023-11-25', 'Theater', 50)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
# Connect to the SQLite database
conn = sqlite3.connect('program_185_database.db')
cursor = conn.cursor()
# Prompt the user for location, event date, and ticket amount
location = input("Enter location: ")
event_date = input("Enter event date (YYYY-MM-DD): ")
ticket_amount = int(input("Enter ticket amount: "))
# Validate event date format
try:
datetime.strptime(event_date, "%Y-%m-%d")
except ValueError:
print("Invalid date format. Please enter date in YYYY-MM-DD format.")
exit()
# Construct the SQL query
query = """
SELECT * FROM events WHERE location = ? AND event_date = ? AND ticket_amount >= ?
"""
# Execute the SQL query
cursor.execute(query, (location, event_date, ticket_amount))
# Fetch all results
results = cursor.fetchall()
# Print the results
if results:
for row in results:
print(row)
else:
print("No matching events found.")
# Close the database connection
conn.close()
|
program_353
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_353_database.db' which contains a table called 'reservations'. This table has the following columns: reservation_id, guest_name, room_type, check_in_date, check_out_date, and price. The task is to query this table based on user inputs. The script should prompt the user to input a room type (e.g., Single, Double, Suite), a check-in date, a check-out date, and a maximum price they are willing to pay. Using these inputs, construct a SQL query to select all reservations that match the specified room type, have a check-in date on or after the specified check-in date, a check-out date on or before the specified check-out date, or have a price less than or equal to the specified maximum price. Execute this query and print out the results.\n\n[Example Input & Output]\n- Input: Double\\n2023-10-01\\n2023-10-03\\n400\\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)\n- Input: Suite\\n2023-10-10\\n2023-10-15\\n900\\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\\n(3, 'Jim Brown', 'Suite', '2023-10-05', '2023-10-10', 750.0)\\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\\n(5, 'Robert Green', 'Double', '2023-10-07', '2023-10-11', 450.0)\\n(6, 'Susan Black', 'Suite', '2023-10-09', '2023-10-14', 800.0)\\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)\\n(8, 'Emily Davis', 'Double', '2023-10-11', '2023-10-15', 500.0)\\n(9, 'David Wilson', 'Suite', '2023-10-13', '2023-10-18', 850.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_353_database.db' which contains a table called 'reservations'. This table has the following columns: reservation_id, guest_name, room_type, check_in_date, check_out_date, and price. The task is to query this table based on user inputs. The script should prompt the user to input a room type (e.g., Single, Double, Suite), a check-in date, a check-out date, and a maximum price they are willing to pay. Using these inputs, construct a SQL query to select all reservations that match the specified room type, have a check-in date on or after the specified check-in date, a check-out date on or before the specified check-out date, or have a price less than or equal to the specified maximum price. Execute this query and print out the results.
[Example Input & Output]
- Input: Double\n2023-10-01\n2023-10-03\n400\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)
- Input: Suite\n2023-10-10\n2023-10-15\n900\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\n(3, 'Jim Brown', 'Suite', '2023-10-05', '2023-10-10', 750.0)\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\n(5, 'Robert Green', 'Double', '2023-10-07', '2023-10-11', 450.0)\n(6, 'Susan Black', 'Suite', '2023-10-09', '2023-10-14', 800.0)\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)\n(8, 'Emily Davis', 'Double', '2023-10-11', '2023-10-15', 500.0)\n(9, 'David Wilson', 'Suite', '2023-10-13', '2023-10-18', 850.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_353_database.db' which contains a table called 'reservations'. This table has the following columns: reservation_id, guest_name, room_type, check_in_date, check_out_date, and price. The task is to query this table based on user inputs. The script should prompt the user to input a room type (e.g., Single, Double, Suite), a check-in date, a check-out date, and a maximum price they are willing to pay. Using these inputs, construct a SQL query to select all reservations that match the specified room type, have a check-in date on or after the specified check-in date, a check-out date on or before the specified check-out date, or have a price less than or equal to the specified maximum price. Execute this query and print out the results.
[Example Input & Output]
- Input: Double\n2023-10-01\n2023-10-03\n400\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)
- Input: Suite\n2023-10-10\n2023-10-15\n900\n ; Output: (1, 'John Doe', 'Single', '2023-10-01', '2023-10-05', 300.0)\n(2, 'Jane Smith', 'Double', '2023-10-03', '2023-10-07', 400.0)\n(3, 'Jim Brown', 'Suite', '2023-10-05', '2023-10-10', 750.0)\n(4, 'Anna White', 'Single', '2023-10-06', '2023-10-08', 200.0)\n(5, 'Robert Green', 'Double', '2023-10-07', '2023-10-11', 450.0)\n(6, 'Susan Black', 'Suite', '2023-10-09', '2023-10-14', 800.0)\n(7, 'Michael Johnson', 'Single', '2023-10-10', '2023-10-12', 250.0)\n(8, 'Emily Davis', 'Double', '2023-10-11', '2023-10-15', 500.0)\n(9, 'David Wilson', 'Suite', '2023-10-13', '2023-10-18', 850.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_353_database.db')
cursor = conn.cursor()
# Prompt user for inputs
room_type = input("Enter room type: ")
check_in_date = input("Enter check-in date (YYYY-MM-DD): ")
check_out_date = input("Enter check-out date (YYYY-MM-DD): ")
max_price = input("Enter maximum price: ")
# Construct SQL query based on user inputs
query = """
SELECT * FROM reservations
WHERE room_type = ? AND check_in_date >= ? AND check_out_date <= ? AND max_price <= ?
"""
# Execute the query
cursor.execute(query, (room_type, check_in_date, check_out_date, max_price))
# Fetch and print all results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_78
|
[
{
"content": "[Problem]\nYou have a database file named 'program_78_database.db' with a table called 'orders'. The table has the following columns: order_id (INTEGER), customer (TEXT), order_date (TEXT), status (TEXT), and total_price (REAL). Your task is to write a Python script that connects to this database and retrieves orders based on user input. The script should prompt the user for four inputs: a start date and an end date in the format 'YYYY-MM-DD', a bulk discount percentage as a number (e.g., 10 for 10%), and an order status to filter by. Additionally, the user should provide a price threshold, and the script should calculate the effective price threshold after applying the discount. The script should then construct and execute an SQL query to select orders where the order_date is between the start and end dates, the status matches the user input, and the total_price is above the calculated threshold. Finally, the script should print the results of the query.\n\n[Example Input & Output]\n- Input: 2023-01-01\\n2023-12-31\\n30\\nPending\\n600\\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]\n- Input: 2023-01-01\\n2023-12-31\\n25\\nPending\\n500\\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_78_database.db' with a table called 'orders'. The table has the following columns: order_id (INTEGER), customer (TEXT), order_date (TEXT), status (TEXT), and total_price (REAL). Your task is to write a Python script that connects to this database and retrieves orders based on user input. The script should prompt the user for four inputs: a start date and an end date in the format 'YYYY-MM-DD', a bulk discount percentage as a number (e.g., 10 for 10%), and an order status to filter by. Additionally, the user should provide a price threshold, and the script should calculate the effective price threshold after applying the discount. The script should then construct and execute an SQL query to select orders where the order_date is between the start and end dates, the status matches the user input, and the total_price is above the calculated threshold. Finally, the script should print the results of the query.
[Example Input & Output]
- Input: 2023-01-01\n2023-12-31\n30\nPending\n600\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]
- Input: 2023-01-01\n2023-12-31\n25\nPending\n500\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_78_database.db' with a table called 'orders'. The table has the following columns: order_id (INTEGER), customer (TEXT), order_date (TEXT), status (TEXT), and total_price (REAL). Your task is to write a Python script that connects to this database and retrieves orders based on user input. The script should prompt the user for four inputs: a start date and an end date in the format 'YYYY-MM-DD', a bulk discount percentage as a number (e.g., 10 for 10%), and an order status to filter by. Additionally, the user should provide a price threshold, and the script should calculate the effective price threshold after applying the discount. The script should then construct and execute an SQL query to select orders where the order_date is between the start and end dates, the status matches the user input, and the total_price is above the calculated threshold. Finally, the script should print the results of the query.
[Example Input & Output]
- Input: 2023-01-01\n2023-12-31\n30\nPending\n600\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]
- Input: 2023-01-01\n2023-12-31\n25\nPending\n500\n ; Output: [(2, 'Bob', '2023-02-17', 'Pending', 500.0), (6, 'Frank', '2023-06-15', 'Pending', 600.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_orders():
# Connect to the SQLite database
conn = sqlite3.connect('program_78_database.db')
cursor = conn.cursor()
# Prompt user for input
start_date = input("Enter start date (YYYY-MM-DD): ")
end_date = input("Enter end date (YYYY-MM-DD): ")
bulk_discount_percentage = float(input("Enter bulk discount percentage: "))
order_status = input("Enter order status: ")
price_threshold = float(input("Enter price threshold: "))
# Calculate effective price threshold after applying the discount
effective_price_threshold = price_threshold * (1 - bulk_discount_percentage / 100)
# Construct and execute the SQL query
query = """
SELECT order_id, customer, order_date, status, total_price
FROM orders
WHERE order_date BETWEEN ? AND ?
AND status = ?
AND total_price > ?
"""
cursor.execute(query, (start_date, end_date, order_status, effective_price_threshold))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function to get orders
get_orders()
|
program_213
|
[
{
"content": "[Problem]\nGiven a database named 'program_213_database.db' with a table called 'inventory', which contains columns 'item_id', 'item_name', 'category', and 'quantity', write a code snippet that connects to this database and retrieves all records from the 'inventory' table where the 'category' matches a user-provided input. The user will provide one input, which is the category of the items they are interested in. The code should then print out all the rows that match this category.\n\n[Example Input & Output]\n- Input: Tools\\n ; Output: (1, 'Widget', 'Tools', 150)\\n(3, 'Screwdriver', 'Tools', 50)\\n(4, 'Hammer', 'Tools', 75)\\n(6, 'Pliers', 'Tools', 30)\\n(7, 'Drill', 'Tools', 20)\\n(8, 'Saw', 'Tools', 60)\\n(9, 'Wrench', 'Tools', 40)\n- Input: Hardware\\n ; Output: (2, 'Bolt', 'Hardware', 300)\\n(5, 'Nail', 'Hardware', 500)\\n(10, 'Nut', 'Hardware', 200)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Given a database named 'program_213_database.db' with a table called 'inventory', which contains columns 'item_id', 'item_name', 'category', and 'quantity', write a code snippet that connects to this database and retrieves all records from the 'inventory' table where the 'category' matches a user-provided input. The user will provide one input, which is the category of the items they are interested in. The code should then print out all the rows that match this category.
[Example Input & Output]
- Input: Tools\n ; Output: (1, 'Widget', 'Tools', 150)\n(3, 'Screwdriver', 'Tools', 50)\n(4, 'Hammer', 'Tools', 75)\n(6, 'Pliers', 'Tools', 30)\n(7, 'Drill', 'Tools', 20)\n(8, 'Saw', 'Tools', 60)\n(9, 'Wrench', 'Tools', 40)
- Input: Hardware\n ; Output: (2, 'Bolt', 'Hardware', 300)\n(5, 'Nail', 'Hardware', 500)\n(10, 'Nut', 'Hardware', 200)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Given a database named 'program_213_database.db' with a table called 'inventory', which contains columns 'item_id', 'item_name', 'category', and 'quantity', write a code snippet that connects to this database and retrieves all records from the 'inventory' table where the 'category' matches a user-provided input. The user will provide one input, which is the category of the items they are interested in. The code should then print out all the rows that match this category.
[Example Input & Output]
- Input: Tools\n ; Output: (1, 'Widget', 'Tools', 150)\n(3, 'Screwdriver', 'Tools', 50)\n(4, 'Hammer', 'Tools', 75)\n(6, 'Pliers', 'Tools', 30)\n(7, 'Drill', 'Tools', 20)\n(8, 'Saw', 'Tools', 60)\n(9, 'Wrench', 'Tools', 40)
- Input: Hardware\n ; Output: (2, 'Bolt', 'Hardware', 300)\n(5, 'Nail', 'Hardware', 500)\n(10, 'Nut', 'Hardware', 200)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_213_database.db')
# Create a cursor object
cursor = conn.cursor()
# Prompt the user to enter a category
category = input("Enter the category: ")
# Construct and execute the SQL query
cursor.execute("SELECT * FROM inventory WHERE category=?", (category,))
# Fetch all matching rows
rows = cursor.fetchall()
# Print the matching rows
for row in rows:
print(row)
# Close the database connection
conn.close()
|
program_24
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_24_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: customer_id, first_name, last_name, age, and city. The task is to query this table to find customers based on user input. The script should prompt the user to input a minimum age, a maximum age, and a target city. Additionally, the user should be asked if they want to include customers younger than the minimum age. Based on these inputs, construct a query to select customers whose age falls within the specified range and who reside in the specified city. The results should be printed to the console.\n\n[Example Input & Output]\n- Input: 37\\n47\\nSan Jose\\nno\\n ; Output: [(10, 'Jasmine', 'Hill', 39, 'San Jose')]\n- Input: 31\\n41\\nPhiladelphia\\nno\\n ; Output: [(6, 'Fiona', 'Gonzalez', 36, 'Philadelphia')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_24_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: customer_id, first_name, last_name, age, and city. The task is to query this table to find customers based on user input. The script should prompt the user to input a minimum age, a maximum age, and a target city. Additionally, the user should be asked if they want to include customers younger than the minimum age. Based on these inputs, construct a query to select customers whose age falls within the specified range and who reside in the specified city. The results should be printed to the console.
[Example Input & Output]
- Input: 37\n47\nSan Jose\nno\n ; Output: [(10, 'Jasmine', 'Hill', 39, 'San Jose')]
- Input: 31\n41\nPhiladelphia\nno\n ; Output: [(6, 'Fiona', 'Gonzalez', 36, 'Philadelphia')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_24_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: customer_id, first_name, last_name, age, and city. The task is to query this table to find customers based on user input. The script should prompt the user to input a minimum age, a maximum age, and a target city. Additionally, the user should be asked if they want to include customers younger than the minimum age. Based on these inputs, construct a query to select customers whose age falls within the specified range and who reside in the specified city. The results should be printed to the console.
[Example Input & Output]
- Input: 37\n47\nSan Jose\nno\n ; Output: [(10, 'Jasmine', 'Hill', 39, 'San Jose')]
- Input: 31\n41\nPhiladelphia\nno\n ; Output: [(6, 'Fiona', 'Gonzalez', 36, 'Philadelphia')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from getpass import getpass
# Connect to the SQLite database
conn = sqlite3.connect('program_24_database.db')
cursor = conn.cursor()
# Prompt the user for input
min_age = int(input("Enter the minimum age: "))
max_age = int(input("Enter the maximum age: "))
target_city = input("Enter the target city: ")
include_younger_than_min = input("Include customers younger than the minimum age? (yes/no): ").strip().lower() == 'yes'
# Construct the SQL query based on user input
query = """
SELECT *
FROM customers
WHERE age BETWEEN ? AND ?
AND city = ?
"""
if include_younger_than_min:
query += " OR age < ?"
# Execute the query with user input
cursor.execute(query, (min_age, max_age, target_city, min_age))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
|
program_248
|
[
{
"content": "[Problem]\nThe database is named 'program_248_database.db' and contains a table called 'orders'. This table has the following columns: 'order_id' (an integer and the primary key), 'item' (a text field), 'category' (a text field), 'price' (a real number), and 'quantity' (an integer). The task is to retrieve all orders from this table that fall within a specified price range and belong to a specific category. The inputs required are three: a minimum price (a floating-point number), a maximum price (a floating-point number), and a category (a string). The output should be a list of orders that match these criteria.\n\n[Example Input & Output]\n- Input: 3.00\\n4.50\\nDessert\\n ; Output: [(10, 'Ice Cream', 'Dessert', 3.99, 90), (11, 'Cake', 'Dessert', 4.49, 60)]\n- Input: 1.00\\n3.00\\nDessert\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_248_database.db' and contains a table called 'orders'. This table has the following columns: 'order_id' (an integer and the primary key), 'item' (a text field), 'category' (a text field), 'price' (a real number), and 'quantity' (an integer). The task is to retrieve all orders from this table that fall within a specified price range and belong to a specific category. The inputs required are three: a minimum price (a floating-point number), a maximum price (a floating-point number), and a category (a string). The output should be a list of orders that match these criteria.
[Example Input & Output]
- Input: 3.00\n4.50\nDessert\n ; Output: [(10, 'Ice Cream', 'Dessert', 3.99, 90), (11, 'Cake', 'Dessert', 4.49, 60)]
- Input: 1.00\n3.00\nDessert\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_248_database.db' and contains a table called 'orders'. This table has the following columns: 'order_id' (an integer and the primary key), 'item' (a text field), 'category' (a text field), 'price' (a real number), and 'quantity' (an integer). The task is to retrieve all orders from this table that fall within a specified price range and belong to a specific category. The inputs required are three: a minimum price (a floating-point number), a maximum price (a floating-point number), and a category (a string). The output should be a list of orders that match these criteria.
[Example Input & Output]
- Input: 3.00\n4.50\nDessert\n ; Output: [(10, 'Ice Cream', 'Dessert', 3.99, 90), (11, 'Cake', 'Dessert', 4.49, 60)]
- Input: 1.00\n3.00\nDessert\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_orders(min_price, max_price, category):
# Connect to the SQLite database
conn = sqlite3.connect('program_248_database.db')
cursor = conn.cursor()
# Construct the SQL query
query = """
SELECT * FROM orders
WHERE price BETWEEN ? AND ?
AND category = ?
"""
# Execute the query
cursor.execute(query, (min_price, max_price, category))
# Fetch all results
results = cursor.fetchall()
# Close the connection
conn.close()
return results
# Prompt the user for input
min_price = float(input("Enter the minimum price: "))
max_price = float(input("Enter the maximum price: "))
category = input("Enter the category: ")
# Call the get_orders function and store the results
orders = get_orders(min_price, max_price, category)
# Print the orders
print(orders)
|
program_295
|
[
{
"content": "[Problem]\nThe database is stored in a file named 'program_295_database.db' and contains a table called 'accounts'. This table has three columns: 'account_id' which is an integer, 'account_holder' which is a text, and 'balance' which is a real number. The task is to connect to this database and retrieve account details based on user input. Specifically, the user will provide two inputs: an account ID and a minimum balance. The goal is to query the 'accounts' table to find and print all records where the 'account_id' matches the user-provided account ID and the 'balance' is greater than or equal to the user-provided minimum balance.\n\n[Example Input & Output]\n- Input: 1\\n11000\\n ; Output: []\n- Input: 6\\n10000\\n ; Output: [(6, 'Frank', 12000.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is stored in a file named 'program_295_database.db' and contains a table called 'accounts'. This table has three columns: 'account_id' which is an integer, 'account_holder' which is a text, and 'balance' which is a real number. The task is to connect to this database and retrieve account details based on user input. Specifically, the user will provide two inputs: an account ID and a minimum balance. The goal is to query the 'accounts' table to find and print all records where the 'account_id' matches the user-provided account ID and the 'balance' is greater than or equal to the user-provided minimum balance.
[Example Input & Output]
- Input: 1\n11000\n ; Output: []
- Input: 6\n10000\n ; Output: [(6, 'Frank', 12000.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is stored in a file named 'program_295_database.db' and contains a table called 'accounts'. This table has three columns: 'account_id' which is an integer, 'account_holder' which is a text, and 'balance' which is a real number. The task is to connect to this database and retrieve account details based on user input. Specifically, the user will provide two inputs: an account ID and a minimum balance. The goal is to query the 'accounts' table to find and print all records where the 'account_id' matches the user-provided account ID and the 'balance' is greater than or equal to the user-provided minimum balance.
[Example Input & Output]
- Input: 1\n11000\n ; Output: []
- Input: 6\n10000\n ; Output: [(6, 'Frank', 12000.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_295_database.db')
cursor = conn.cursor()
# Prompt the user for an account ID and a minimum balance
account_id = int(input("Enter the account ID: "))
min_balance = float(input("Enter the minimum balance: "))
# Execute the SQL query
cursor.execute("SELECT account_id, account_holder, balance FROM accounts WHERE account_id = ? AND balance >= ?", (account_id, min_balance))
# Fetch all results
results = cursor.fetchall()
# Print the results
if results:
print("Account ID\tAccount Holder\tBalance")
for row in results:
print(f"{row[0]}\t{row[1]}\t{row[2]}")
else:
print("No matching accounts found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_235
|
[
{
"content": "[Problem]\nWe have a database file named 'program_235_database.db' which contains a table called 'products'. This table has four columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to write a code snippet that connects to this database and retrieves all products from the 'products' table that belong to a specific category. The results should be sorted based on a specified column and direction. The code should take six inputs: the category to filter by, a maximum price, an ID value, a search term, the column name to sort by, and the sort direction (either 'ASC' or 'DESC'). The code should then print the results of the query.\n\n[Example Input & Output]\n- Input: Clothing\\n100\\n8\\njacket\\nid\\nDESC\\n ; Output: [(8, 'Sneakers', 'Clothing', 80.0), (7, 'Jacket', 'Clothing', 120.0), (4, 'Jeans', 'Clothing', 50.0), (3, 'Shirt', 'Clothing', 30.0)]\n- Input: Clothing\\n100\\n4\\nsneakers\\ncategory\\nASC\\n ; Output: [(3, 'Shirt', 'Clothing', 30.0), (4, 'Jeans', 'Clothing', 50.0), (7, 'Jacket', 'Clothing', 120.0), (8, 'Sneakers', 'Clothing', 80.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_235_database.db' which contains a table called 'products'. This table has four columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to write a code snippet that connects to this database and retrieves all products from the 'products' table that belong to a specific category. The results should be sorted based on a specified column and direction. The code should take six inputs: the category to filter by, a maximum price, an ID value, a search term, the column name to sort by, and the sort direction (either 'ASC' or 'DESC'). The code should then print the results of the query.
[Example Input & Output]
- Input: Clothing\n100\n8\njacket\nid\nDESC\n ; Output: [(8, 'Sneakers', 'Clothing', 80.0), (7, 'Jacket', 'Clothing', 120.0), (4, 'Jeans', 'Clothing', 50.0), (3, 'Shirt', 'Clothing', 30.0)]
- Input: Clothing\n100\n4\nsneakers\ncategory\nASC\n ; Output: [(3, 'Shirt', 'Clothing', 30.0), (4, 'Jeans', 'Clothing', 50.0), (7, 'Jacket', 'Clothing', 120.0), (8, 'Sneakers', 'Clothing', 80.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_235_database.db' which contains a table called 'products'. This table has four columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to write a code snippet that connects to this database and retrieves all products from the 'products' table that belong to a specific category. The results should be sorted based on a specified column and direction. The code should take six inputs: the category to filter by, a maximum price, an ID value, a search term, the column name to sort by, and the sort direction (either 'ASC' or 'DESC'). The code should then print the results of the query.
[Example Input & Output]
- Input: Clothing\n100\n8\njacket\nid\nDESC\n ; Output: [(8, 'Sneakers', 'Clothing', 80.0), (7, 'Jacket', 'Clothing', 120.0), (4, 'Jeans', 'Clothing', 50.0), (3, 'Shirt', 'Clothing', 30.0)]
- Input: Clothing\n100\n4\nsneakers\ncategory\nASC\n ; Output: [(3, 'Shirt', 'Clothing', 30.0), (4, 'Jeans', 'Clothing', 50.0), (7, 'Jacket', 'Clothing', 120.0), (8, 'Sneakers', 'Clothing', 80.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def fetch_products(category, max_price, id_value, search_term, sort_column, sort_direction):
# Connect to the SQLite database
conn = sqlite3.connect('program_235_database.db')
cursor = conn.cursor()
# Construct the SQL query
query = """
SELECT id, name, category, price
FROM products
WHERE category = ?
AND price <= ?
AND id != ?
AND name LIKE ?
ORDER BY ? ASC;
"""
# Execute the query with parameters
cursor.execute(query, (category, max_price, id_value, f'%{search_term}%', sort_column))
# Fetch all results
results = cursor.fetchall()
# Close the connection
conn.close()
return results
# Prompt the user for input
category = input("Enter category: ")
max_price = float(input("Enter max price: "))
id_value = int(input("Enter id value: "))
search_term = input("Enter search term: ")
sort_column = input("Enter sort column: ")
sort_direction = input("Enter sort direction (ASC/DESC): ")
# Call the function and print the results
results = fetch_products(category, max_price, id_value, search_term, sort_column, sort_direction)
print(results)
|
program_217
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_217_database.db' and queries a table called 'billing'. The table has the following columns: id (INTEGER), customer_name (TEXT), billing_date (TEXT), amount_due (REAL), and status (TEXT). The task is to retrieve all records from the 'billing' table where the billing_date falls between a user-provided start date and end date, the amount_due is greater than or equal to a user-provided minimum amount, and the status matches a user-provided payment status. The script should prompt the user for four inputs: start date (in the format YYYY-MM-DD), end date (in the format YYYY-MM-DD), minimum amount due (a number), and payment status (a string such as 'Pending' or 'Paid'). After executing the query, the script should print the results.\n\n[Example Input & Output]\n- Input: 2023-09-25\\n2023-10-05\\n120\\nPending\\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending')]\n- Input: 2023-09-01\\n2023-10-31\\n50\\nPending\\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending'), (3, 'Mike Jones', '2023-10-10', 200.0, 'Pending'), (5, 'Bob White', '2023-10-05', 95.0, 'Pending'), (7, 'Diana Green', '2023-10-08', 180.0, 'Pending')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_217_database.db' and queries a table called 'billing'. The table has the following columns: id (INTEGER), customer_name (TEXT), billing_date (TEXT), amount_due (REAL), and status (TEXT). The task is to retrieve all records from the 'billing' table where the billing_date falls between a user-provided start date and end date, the amount_due is greater than or equal to a user-provided minimum amount, and the status matches a user-provided payment status. The script should prompt the user for four inputs: start date (in the format YYYY-MM-DD), end date (in the format YYYY-MM-DD), minimum amount due (a number), and payment status (a string such as 'Pending' or 'Paid'). After executing the query, the script should print the results.
[Example Input & Output]
- Input: 2023-09-25\n2023-10-05\n120\nPending\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending')]
- Input: 2023-09-01\n2023-10-31\n50\nPending\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending'), (3, 'Mike Jones', '2023-10-10', 200.0, 'Pending'), (5, 'Bob White', '2023-10-05', 95.0, 'Pending'), (7, 'Diana Green', '2023-10-08', 180.0, 'Pending')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_217_database.db' and queries a table called 'billing'. The table has the following columns: id (INTEGER), customer_name (TEXT), billing_date (TEXT), amount_due (REAL), and status (TEXT). The task is to retrieve all records from the 'billing' table where the billing_date falls between a user-provided start date and end date, the amount_due is greater than or equal to a user-provided minimum amount, and the status matches a user-provided payment status. The script should prompt the user for four inputs: start date (in the format YYYY-MM-DD), end date (in the format YYYY-MM-DD), minimum amount due (a number), and payment status (a string such as 'Pending' or 'Paid'). After executing the query, the script should print the results.
[Example Input & Output]
- Input: 2023-09-25\n2023-10-05\n120\nPending\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending')]
- Input: 2023-09-01\n2023-10-31\n50\nPending\n ; Output: [(1, 'John Doe', '2023-10-01', 120.5, 'Pending'), (3, 'Mike Jones', '2023-10-10', 200.0, 'Pending'), (5, 'Bob White', '2023-10-05', 95.0, 'Pending'), (7, 'Diana Green', '2023-10-08', 180.0, 'Pending')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_217_database.db')
cursor = conn.cursor()
# Prompt the user for input
start_date_str = input("Enter start date (YYYY-MM-DD): ")
end_date_str = input("Enter end date (YYYY-MM-DD): ")
min_amount_due = float(input("Enter minimum amount due: "))
payment_status = input("Enter payment status (Pending/Paid): ")
# Validate the payment status
if payment_status not in ['Pending', 'Paid']:
print("Invalid payment status. Please enter 'Pending' or 'Paid'.")
return
# Convert the input strings to datetime objects
try:
start_date = datetime.strptime(start_date_str, '%Y-%m-%d')
end_date = datetime.strptime(end_date_str, '%Y-%m-%d')
except ValueError:
print("Invalid date format. Please use YYYY-MM-DD.")
return
# Construct the SQL query
query = """
SELECT *
FROM billing
WHERE billing_date BETWEEN ? AND ?
AND amount_due >= ?
AND status = ?
"""
# Execute the query
cursor.execute(query, (start_date, end_date, min_amount_due, payment_status))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_174
|
[
{
"content": "[Problem]\nThe database is named 'program_174_database.db' and contains a table called 'studies'. This table has four columns: 'study_id', 'researcher', 'research_subject', and 'findings'. The task is to retrieve and print all the data from the 'studies' table for a specific researcher. The input required is the name of the researcher, which will be used to filter the results. The expected input is a single string representing the researcher's name. Use this input to query the 'studies' table and print the results.\n\n[Example Input & Output]\n- Input: Bob\\n ; Output: (2, 'Bob', 'Genetics', 'Gene editing advancements.')\n- Input: Frank\\n ; Output: (6, 'Frank', 'Neuroscience', 'Insights into brain plasticity.')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_174_database.db' and contains a table called 'studies'. This table has four columns: 'study_id', 'researcher', 'research_subject', and 'findings'. The task is to retrieve and print all the data from the 'studies' table for a specific researcher. The input required is the name of the researcher, which will be used to filter the results. The expected input is a single string representing the researcher's name. Use this input to query the 'studies' table and print the results.
[Example Input & Output]
- Input: Bob\n ; Output: (2, 'Bob', 'Genetics', 'Gene editing advancements.')
- Input: Frank\n ; Output: (6, 'Frank', 'Neuroscience', 'Insights into brain plasticity.')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_174_database.db' and contains a table called 'studies'. This table has four columns: 'study_id', 'researcher', 'research_subject', and 'findings'. The task is to retrieve and print all the data from the 'studies' table for a specific researcher. The input required is the name of the researcher, which will be used to filter the results. The expected input is a single string representing the researcher's name. Use this input to query the 'studies' table and print the results.
[Example Input & Output]
- Input: Bob\n ; Output: (2, 'Bob', 'Genetics', 'Gene editing advancements.')
- Input: Frank\n ; Output: (6, 'Frank', 'Neuroscience', 'Insights into brain plasticity.')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import os
def get_researcher_data(researcher_name):
# Connect to the SQLite database
conn = sqlite3.connect('program_174_database.db')
cursor = conn.cursor()
# Retrieve data for the specified researcher
query = "SELECT * FROM researchers WHERE name = ?"
cursor.execute(query, (researcher_name,))
data = cursor.fetchall()
# Close the database connection
conn.close()
return data
def main():
# Prompt the user to enter a researcher's name
researcher_name = input("Enter the researcher's name: ")
# Retrieve data from the database
data = get_researcher_data(researcher_name)
# Print the results
if data:
print("Researcher Data:")
for row in data:
print(row)
else:
print("No data found for the specified researcher.")
if __name__ == "__main__":
main()
|
program_315
|
[
{
"content": "[Problem]\nWe have a database file named 'program_315_database.db' which contains a table called 'campaigns'. This table has the following columns: campaign_id, name, start_date, end_date, audience_size, and conversions. The task is to write a Python script that connects to this database and retrieves campaigns based on user inputs. The script should prompt the user to input a start date, an end date, a minimum audience size, and a desired conversion ratio. Using these inputs, the script should construct an SQL query to select campaigns where the start date is on or after the given start date, the end date is on or before the given end date, the audience size is greater than the specified minimum, or the number of conversions is greater than or equal to the product of the audience size and the conversion ratio. Finally, the script should execute this query and print the results.\n\n[Example Input & Output]\n- Input: 2023-01-01\\n2023-12-31\\n25000\\n0.07\\n ; Output: [(3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]\n- Input: 2023-09-01\\n2023-12-31\\n20000\\n0.07\\n ; Output: [(2, 'Summer Sale', '2023-06-01', '2023-06-30', 20000, 1500), (3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_315_database.db' which contains a table called 'campaigns'. This table has the following columns: campaign_id, name, start_date, end_date, audience_size, and conversions. The task is to write a Python script that connects to this database and retrieves campaigns based on user inputs. The script should prompt the user to input a start date, an end date, a minimum audience size, and a desired conversion ratio. Using these inputs, the script should construct an SQL query to select campaigns where the start date is on or after the given start date, the end date is on or before the given end date, the audience size is greater than the specified minimum, or the number of conversions is greater than or equal to the product of the audience size and the conversion ratio. Finally, the script should execute this query and print the results.
[Example Input & Output]
- Input: 2023-01-01\n2023-12-31\n25000\n0.07\n ; Output: [(3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]
- Input: 2023-09-01\n2023-12-31\n20000\n0.07\n ; Output: [(2, 'Summer Sale', '2023-06-01', '2023-06-30', 20000, 1500), (3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_315_database.db' which contains a table called 'campaigns'. This table has the following columns: campaign_id, name, start_date, end_date, audience_size, and conversions. The task is to write a Python script that connects to this database and retrieves campaigns based on user inputs. The script should prompt the user to input a start date, an end date, a minimum audience size, and a desired conversion ratio. Using these inputs, the script should construct an SQL query to select campaigns where the start date is on or after the given start date, the end date is on or before the given end date, the audience size is greater than the specified minimum, or the number of conversions is greater than or equal to the product of the audience size and the conversion ratio. Finally, the script should execute this query and print the results.
[Example Input & Output]
- Input: 2023-01-01\n2023-12-31\n25000\n0.07\n ; Output: [(3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]
- Input: 2023-09-01\n2023-12-31\n20000\n0.07\n ; Output: [(2, 'Summer Sale', '2023-06-01', '2023-06-30', 20000, 1500), (3, 'Black Friday Blast', '2023-11-25', '2023-11-29', 50000, 8000), (4, 'Holiday Special', '2023-12-01', '2023-12-31', 30000, 2500), (6, 'Back to School', '2023-08-01', '2023-08-31', 25000, 1800), (7, 'End of Year Clearance', '2023-12-26', '2023-12-31', 40000, 3500)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def get_campaigns():
# Connect to the SQLite database
conn = sqlite3.connect('program_315_database.db')
cursor = conn.cursor()
# Prompt the user for input
start_date_str = input("Enter start date (YYYY-MM-DD): ")
end_date_str = input("Enter end date (YYYY-MM-DD): ")
min_audience_size = int(input("Enter minimum audience size: "))
conversion_ratio = float(input("Enter conversion ratio: "))
# Validate dates
try:
start_date = datetime.strptime(start_date_str, '%Y-%m-%d')
end_date = datetime.strptime(end_date_str, '%Y-%m-%d')
except ValueError:
print("Invalid date format. Please use YYYY-MM-DD.")
return
# Construct the SQL query
query = """
SELECT campaign_id, name, start_date, end_date, audience_size, conversions
FROM campaigns
WHERE start_date >= ? AND end_date <= ? AND (
audience_size > ? OR conversions >= ?
)
"""
# Execute the query
cursor.execute(query, (start_date, end_date, min_audience_size, conversion_ratio * min_audience_size))
results = cursor.fetchall()
# Print each result
for result in results:
print(result)
# Close the database connection
conn.close()
# Call the function
get_campaigns()
|
program_75
|
[
{
"content": "[Problem]\nWe have a SQLite database file named 'program_75_database.db' which contains a table called 'items'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), 'weight' (REAL), and 'rating' (REAL). The task is to write a Python script that connects to this database and retrieves all items from the 'items' table based on user inputs. The user will provide four inputs: a minimum weight, a maximum weight, a minimum rating, and a desired category. The script should calculate a range for the weight by adjusting the minimum weight to 95% of the input value and the maximum weight to 105% of the input value. It should also adjust the minimum rating by adding 0.3 to the input value. The script should then query the database to find all items that fall within the calculated weight range, have a rating greater than or equal to the adjusted minimum rating, and belong to the specified category. Finally, the script should print the results of this query.\n\n[Example Input & Output]\n- Input: 15\\n35\\n3.9\\nAppliances\\n ; Output: []\n- Input: 250\\n300\\n4.0\\nAppliances\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a SQLite database file named 'program_75_database.db' which contains a table called 'items'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), 'weight' (REAL), and 'rating' (REAL). The task is to write a Python script that connects to this database and retrieves all items from the 'items' table based on user inputs. The user will provide four inputs: a minimum weight, a maximum weight, a minimum rating, and a desired category. The script should calculate a range for the weight by adjusting the minimum weight to 95% of the input value and the maximum weight to 105% of the input value. It should also adjust the minimum rating by adding 0.3 to the input value. The script should then query the database to find all items that fall within the calculated weight range, have a rating greater than or equal to the adjusted minimum rating, and belong to the specified category. Finally, the script should print the results of this query.
[Example Input & Output]
- Input: 15\n35\n3.9\nAppliances\n ; Output: []
- Input: 250\n300\n4.0\nAppliances\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a SQLite database file named 'program_75_database.db' which contains a table called 'items'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), 'weight' (REAL), and 'rating' (REAL). The task is to write a Python script that connects to this database and retrieves all items from the 'items' table based on user inputs. The user will provide four inputs: a minimum weight, a maximum weight, a minimum rating, and a desired category. The script should calculate a range for the weight by adjusting the minimum weight to 95% of the input value and the maximum weight to 105% of the input value. It should also adjust the minimum rating by adding 0.3 to the input value. The script should then query the database to find all items that fall within the calculated weight range, have a rating greater than or equal to the adjusted minimum rating, and belong to the specified category. Finally, the script should print the results of this query.
[Example Input & Output]
- Input: 15\n35\n3.9\nAppliances\n ; Output: []
- Input: 250\n300\n4.0\nAppliances\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import os
import sqlite3
def fetch_items():
try:
# Connect to the SQLite database
conn = sqlite3.connect('program_75_database.db')
cursor = conn.cursor()
# Retrieve user input criteria from environment variables
min_weight = float(os.getenv('MIN_WEIGHT'))
max_weight = float(os.getenv('MAX_WEIGHT'))
min_rating = float(os.getenv('MIN_RATING'))
category = os.getenv('CATEGORY')
# Adjust weight and rating values
adjusted_min_weight = min_weight * 1.05 # Example adjustment
adjusted_max_weight = max_weight * 0.95 # Example adjustment
adjusted_min_rating = min_rating * 1.10 # Example adjustment
# Construct and execute the SQL query
query = """
SELECT * FROM items
WHERE weight BETWEEN ? AND ?
AND rating BETWEEN ? AND ?
AND category = ?
"""
cursor.execute(query, (adjusted_min_weight, adjusted_max_weight, adjusted_min_rating, max_rating, category))
# Fetch and print the results
results = cursor.fetchall()
for item in results:
print(item)
except sqlite3.Error as e:
print(f"An error occurred: {e}")
finally:
# Close the database connection
if conn:
conn.close()
# Call the function to execute the query
fetch_items()
|
program_401
|
[
{
"content": "[Problem]\nWe have a database file named 'program_401_database.db' which contains a table called 'books'. This table has the following columns: 'book_id' (an integer primary key), 'title' (text), 'author' (text), 'genre' (text), and 'price' (real). The task is to connect to this database and execute a SQL query to search for books based on user input. Specifically, the program should prompt the user to input a book title and an author name. Using these inputs, construct a SQL query to select all columns from the 'books' table where the 'title' matches the input title and the 'author' matches the input author. After executing the query, fetch and print all the results. Finally, ensure the database connection is properly closed after the operation.\n\n[Example Input & Output]\n- Input: The Hobbit\\nJ.R.R. Tolkien\\n ; Output: (7, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 12.99)\n- Input: 1984\\nGeorge Orwell\\n ; Output: (3, '1984', 'George Orwell', 'Dystopian', 8.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_401_database.db' which contains a table called 'books'. This table has the following columns: 'book_id' (an integer primary key), 'title' (text), 'author' (text), 'genre' (text), and 'price' (real). The task is to connect to this database and execute a SQL query to search for books based on user input. Specifically, the program should prompt the user to input a book title and an author name. Using these inputs, construct a SQL query to select all columns from the 'books' table where the 'title' matches the input title and the 'author' matches the input author. After executing the query, fetch and print all the results. Finally, ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: The Hobbit\nJ.R.R. Tolkien\n ; Output: (7, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 12.99)
- Input: 1984\nGeorge Orwell\n ; Output: (3, '1984', 'George Orwell', 'Dystopian', 8.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_401_database.db' which contains a table called 'books'. This table has the following columns: 'book_id' (an integer primary key), 'title' (text), 'author' (text), 'genre' (text), and 'price' (real). The task is to connect to this database and execute a SQL query to search for books based on user input. Specifically, the program should prompt the user to input a book title and an author name. Using these inputs, construct a SQL query to select all columns from the 'books' table where the 'title' matches the input title and the 'author' matches the input author. After executing the query, fetch and print all the results. Finally, ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: The Hobbit\nJ.R.R. Tolkien\n ; Output: (7, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 12.99)
- Input: 1984\nGeorge Orwell\n ; Output: (3, '1984', 'George Orwell', 'Dystopian', 8.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_401_database.db')
cursor = conn.cursor()
# Prompt the user for book title and author
book_title = input("Enter book title: ")
book_author = input("Enter author name: ")
# Execute the query to find books matching the user input
cursor.execute("SELECT * FROM books WHERE title = ? AND author = ?", (book_title, book_author))
# Fetch all results
results = cursor.fetchall()
# Print the results
if results:
print("Books found:")
for row in results:
print(f"Title: {row[0]}, Author: {row[1]}")
else:
print("No books found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_348
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_348_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id (INTEGER), item (TEXT), quantity (INTEGER), price (REAL), and customer (TEXT). The task is to prompt the user for three inputs: a customer name (case-sensitive), a minimum price, and a maximum price. Use these inputs to retrieve and print all orders from the 'orders' table where the customer matches the given name and the price is between the specified minimum and maximum values.\n\n[Example Input & Output]\n- Input: Eva\\n5\\n15\\n ; Output: [(5, 'Sushi', 1, 10.99, 'Eva')]\n- Input: Henry\\n3\\n3.5\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_348_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id (INTEGER), item (TEXT), quantity (INTEGER), price (REAL), and customer (TEXT). The task is to prompt the user for three inputs: a customer name (case-sensitive), a minimum price, and a maximum price. Use these inputs to retrieve and print all orders from the 'orders' table where the customer matches the given name and the price is between the specified minimum and maximum values.
[Example Input & Output]
- Input: Eva\n5\n15\n ; Output: [(5, 'Sushi', 1, 10.99, 'Eva')]
- Input: Henry\n3\n3.5\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_348_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id (INTEGER), item (TEXT), quantity (INTEGER), price (REAL), and customer (TEXT). The task is to prompt the user for three inputs: a customer name (case-sensitive), a minimum price, and a maximum price. Use these inputs to retrieve and print all orders from the 'orders' table where the customer matches the given name and the price is between the specified minimum and maximum values.
[Example Input & Output]
- Input: Eva\n5\n15\n ; Output: [(5, 'Sushi', 1, 10.99, 'Eva')]
- Input: Henry\n3\n3.5\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from getpass import getpass
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_348_database.db')
cursor = conn.cursor()
# Prompt the user for input
customer_name = input("Enter customer name: ")
min_price = float(input("Enter minimum price: "))
max_price = float(input("Enter maximum price: "))
# Construct the SQL query
query = """
SELECT * FROM orders
WHERE customer_name = ? AND price BETWEEN ? AND ?
"""
# Execute the query
cursor.execute(query, (customer_name, min_price, max_price))
# Fetch and print all the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_231
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_231_database.db' and queries a table called 'transactions'. The table has the following columns: transaction_id, account_number, amount, transaction_date, and description. The task is to prompt the user for two inputs: an account number and a minimum transaction amount. Use these inputs to filter and retrieve all transactions from the 'transactions' table where the account number matches the user input and the transaction amount is greater than or equal to the specified minimum amount. Print the results of this query.\n\n[Example Input & Output]\n- Input: 0987654321\\n400\\n ; Output: (5, '0987654321', 500.0, '2023-11-05', 'Bonus Credit')\n- Input: 1234567890\\n-200\\n ; Output: (1, '1234567890', 1500.0, '2023-11-01', 'Salary Credit')\\n(3, '1234567890', -100.0, '2023-11-03', 'Grocery Shopping')\\n(4, '1234567890', -200.0, '2023-11-04', 'Online Shopping')\\n(6, '1234567890', -50.0, '2023-11-06', 'Restaurant Bill')\\n(8, '1234567890', 400.0, '2023-11-08', 'Freelance Payment')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_231_database.db' and queries a table called 'transactions'. The table has the following columns: transaction_id, account_number, amount, transaction_date, and description. The task is to prompt the user for two inputs: an account number and a minimum transaction amount. Use these inputs to filter and retrieve all transactions from the 'transactions' table where the account number matches the user input and the transaction amount is greater than or equal to the specified minimum amount. Print the results of this query.
[Example Input & Output]
- Input: 0987654321\n400\n ; Output: (5, '0987654321', 500.0, '2023-11-05', 'Bonus Credit')
- Input: 1234567890\n-200\n ; Output: (1, '1234567890', 1500.0, '2023-11-01', 'Salary Credit')\n(3, '1234567890', -100.0, '2023-11-03', 'Grocery Shopping')\n(4, '1234567890', -200.0, '2023-11-04', 'Online Shopping')\n(6, '1234567890', -50.0, '2023-11-06', 'Restaurant Bill')\n(8, '1234567890', 400.0, '2023-11-08', 'Freelance Payment')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_231_database.db' and queries a table called 'transactions'. The table has the following columns: transaction_id, account_number, amount, transaction_date, and description. The task is to prompt the user for two inputs: an account number and a minimum transaction amount. Use these inputs to filter and retrieve all transactions from the 'transactions' table where the account number matches the user input and the transaction amount is greater than or equal to the specified minimum amount. Print the results of this query.
[Example Input & Output]
- Input: 0987654321\n400\n ; Output: (5, '0987654321', 500.0, '2023-11-05', 'Bonus Credit')
- Input: 1234567890\n-200\n ; Output: (1, '1234567890', 1500.0, '2023-11-01', 'Salary Credit')\n(3, '1234567890', -100.0, '2023-11-03', 'Grocery Shopping')\n(4, '1234567890', -200.0, '2023-11-04', 'Online Shopping')\n(6, '1234567890', -50.0, '2023-11-06', 'Restaurant Bill')\n(8, '1234567890', 400.0, '2023-11-08', 'Freelance Payment')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_231_database.db')
cursor = conn.cursor()
# Prompt the user for account number and minimum transaction amount
account_number = input("Enter account number: ")
min_transaction_amount = float(input("Enter minimum transaction amount: "))
# Execute the SQL query to retrieve transactions
cursor.execute("SELECT * FROM transactions WHERE account_number=? AND amount>=?", (account_number, min_transaction_amount))
# Fetch and print the results
transactions = cursor.fetchall()
if transactions:
print("Transactions:")
for transaction in transactions:
print(transaction)
else:
print("No transactions found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_245
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_245_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), supplier (TEXT), quantity (INTEGER), and price_per_unit (REAL). The task is to allow a user to search for items in the inventory based on specific criteria. The user should be prompted to input the name of the item, the supplier's name, and a minimum quantity. The script should then execute a query to retrieve and print all items from the inventory that match the given item name, supplier, and have a quantity greater than or equal to the specified minimum quantity. Additionally, include a function to display all items in the inventory. Ensure the script closes the database connection properly after executing the queries.\n\n[Example Input & Output]\n- Input: Drill\\nToolInc\\n10\\n ; Output: (1004, 'Drill', 'ToolInc', 30, 45.0)\\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\\n(1004, 'Drill', 'ToolInc', 30, 45.0)\\n(1005, 'Saw', 'ToolInc', 25, 22.5)\\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\\n(1009, 'Level', 'MeasureCo', 70, 9.5)\\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)\n- Input: Nails\\nHardwareCo\\n150\\n ; Output: (1002, 'Nails', 'HardwareCo', 200, 0.02)\\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\\n(1004, 'Drill', 'ToolInc', 30, 45.0)\\n(1005, 'Saw', 'ToolInc', 25, 22.5)\\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\\n(1009, 'Level', 'MeasureCo', 70, 9.5)\\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_245_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), supplier (TEXT), quantity (INTEGER), and price_per_unit (REAL). The task is to allow a user to search for items in the inventory based on specific criteria. The user should be prompted to input the name of the item, the supplier's name, and a minimum quantity. The script should then execute a query to retrieve and print all items from the inventory that match the given item name, supplier, and have a quantity greater than or equal to the specified minimum quantity. Additionally, include a function to display all items in the inventory. Ensure the script closes the database connection properly after executing the queries.
[Example Input & Output]
- Input: Drill\nToolInc\n10\n ; Output: (1004, 'Drill', 'ToolInc', 30, 45.0)\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\n(1004, 'Drill', 'ToolInc', 30, 45.0)\n(1005, 'Saw', 'ToolInc', 25, 22.5)\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\n(1009, 'Level', 'MeasureCo', 70, 9.5)\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)
- Input: Nails\nHardwareCo\n150\n ; Output: (1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\n(1004, 'Drill', 'ToolInc', 30, 45.0)\n(1005, 'Saw', 'ToolInc', 25, 22.5)\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\n(1009, 'Level', 'MeasureCo', 70, 9.5)\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_245_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), supplier (TEXT), quantity (INTEGER), and price_per_unit (REAL). The task is to allow a user to search for items in the inventory based on specific criteria. The user should be prompted to input the name of the item, the supplier's name, and a minimum quantity. The script should then execute a query to retrieve and print all items from the inventory that match the given item name, supplier, and have a quantity greater than or equal to the specified minimum quantity. Additionally, include a function to display all items in the inventory. Ensure the script closes the database connection properly after executing the queries.
[Example Input & Output]
- Input: Drill\nToolInc\n10\n ; Output: (1004, 'Drill', 'ToolInc', 30, 45.0)\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\n(1004, 'Drill', 'ToolInc', 30, 45.0)\n(1005, 'Saw', 'ToolInc', 25, 22.5)\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\n(1009, 'Level', 'MeasureCo', 70, 9.5)\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)
- Input: Nails\nHardwareCo\n150\n ; Output: (1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1001, 'Screws', 'HardwareCo', 150, 0.05)\n(1002, 'Nails', 'HardwareCo', 200, 0.02)\n(1003, 'Hammer', 'ToolInc', 50, 15.0)\n(1004, 'Drill', 'ToolInc', 30, 45.0)\n(1005, 'Saw', 'ToolInc', 25, 22.5)\n(1006, 'Wrench', 'ToolInc', 60, 12.0)\n(1007, 'Pliers', 'ToolInc', 40, 8.0)\n(1008, 'Tape Measure', 'MeasureCo', 100, 5.75)\n(1009, 'Level', 'MeasureCo', 70, 9.5)\n(1010, 'Screwdriver', 'ToolInc', 80, 4.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def display_all_items():
conn = sqlite3.connect('program_245_database.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM inventory")
items = cursor.fetchall()
for item in items:
print(item)
conn.close()
def search_inventory():
conn = sqlite3.connect('program_245_database.db')
cursor = conn.cursor()
item_name = input("Enter item name: ")
supplier_name = input("Enter supplier's name: ")
min_quantity = int(input("Enter minimum quantity: "))
cursor.execute("SELECT * FROM inventory WHERE item_name=? AND supplier_name=? AND quantity>=?", (item_name, supplier_name, min_quantity))
results = cursor.fetchall()
if results:
for result in results:
print(result)
else:
print("No matching items found.")
conn.close()
|
program_445
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_445_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER), first_name (TEXT), last_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user to input an employee ID and then retrieve and print all the details of the employee with that ID from the 'employees' table. The input should be a single integer representing the employee ID.\n\n[Example Input & Output]\n- Input: 2\\n ; Output: (2, 'Bob', 'Smith', 'Engineering', 85000.0)\n- Input: 9\\n ; Output: (9, 'Ian', 'Anderson', 'Sales', 62000.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_445_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER), first_name (TEXT), last_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user to input an employee ID and then retrieve and print all the details of the employee with that ID from the 'employees' table. The input should be a single integer representing the employee ID.
[Example Input & Output]
- Input: 2\n ; Output: (2, 'Bob', 'Smith', 'Engineering', 85000.0)
- Input: 9\n ; Output: (9, 'Ian', 'Anderson', 'Sales', 62000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_445_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER), first_name (TEXT), last_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user to input an employee ID and then retrieve and print all the details of the employee with that ID from the 'employees' table. The input should be a single integer representing the employee ID.
[Example Input & Output]
- Input: 2\n ; Output: (2, 'Bob', 'Smith', 'Engineering', 85000.0)
- Input: 9\n ; Output: (9, 'Ian', 'Anderson', 'Sales', 62000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import os
def get_employee_details(employee_id):
# Connect to the SQLite database
conn = sqlite3.connect('program_445_database.db')
cursor = conn.cursor()
# Retrieve the employee details from the database
cursor.execute("SELECT * FROM employees WHERE id = ?", (employee_id,))
employee = cursor.fetchone()
if employee:
print(f"Employee ID: {employee[0]}")
print(f"Name: {employee[1]}")
print(f"Department: {employee[2]}")
print(f"Position: {employee[3]}")
else:
print("Employee not found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
# Prompt the user to input an employee ID
employee_id = int(input("Enter Employee ID: "))
# Retrieve and print the employee details
get_employee_details(employee_id)
|
program_418
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_418_database.db' and interacts with a table called 'patients'. The 'patients' table contains the following columns: id, name, age, diagnosis, and treatment. The task is to retrieve and print all records from the 'patients' table where the name matches a user-provided input. The script should prompt the user to enter a patient's name and then execute a SQL query to fetch and display the corresponding records. If no records are found, it should print a message indicating that no records were found.\n\n[Example Input & Output]\n- Input: David\\n ; Output: No records found.\n- Input: Frank\\n ; Output: (6, 'Frank', 30, 'Back Pain', 'Physical therapy')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_418_database.db' and interacts with a table called 'patients'. The 'patients' table contains the following columns: id, name, age, diagnosis, and treatment. The task is to retrieve and print all records from the 'patients' table where the name matches a user-provided input. The script should prompt the user to enter a patient's name and then execute a SQL query to fetch and display the corresponding records. If no records are found, it should print a message indicating that no records were found.
[Example Input & Output]
- Input: David\n ; Output: No records found.
- Input: Frank\n ; Output: (6, 'Frank', 30, 'Back Pain', 'Physical therapy')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_418_database.db' and interacts with a table called 'patients'. The 'patients' table contains the following columns: id, name, age, diagnosis, and treatment. The task is to retrieve and print all records from the 'patients' table where the name matches a user-provided input. The script should prompt the user to enter a patient's name and then execute a SQL query to fetch and display the corresponding records. If no records are found, it should print a message indicating that no records were found.
[Example Input & Output]
- Input: David\n ; Output: No records found.
- Input: Frank\n ; Output: (6, 'Frank', 30, 'Back Pain', 'Physical therapy')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_418_database.db')
# Create a cursor object using the cursor method
cursor = conn.cursor()
# Prompt the user to enter a patient's name
patient_name = input("Enter patient's name: ")
# Construct and execute the SQL query
cursor.execute("SELECT * FROM patients WHERE name=?", (patient_name,))
# Fetch all records from the executed query
records = cursor.fetchall()
# Check if any records were found
if records:
# Print the records if found
for record in records:
print(record)
else:
# Print a message if no records were found
print("No records found for the given patient name.")
# Close the database connection
conn.close()
|
program_393
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_393_database.db' and interacts with a table called 'students'. The table has the following columns: 'student_id' (INTEGER), 'name' (TEXT), 'major' (TEXT), and 'gpa' (REAL). The task is to prompt the user to input a student ID and then retrieve and print the record from the 'students' table that matches the given student ID. The input should be a single student ID, and the output should display the corresponding student's record. Ensure the connection to the database is properly closed after executing the query.\n\n[Example Input & Output]\n- Input: 104\\n ; Output: (104, 'David Wilson', 'Engineering', 3.7)\n- Input: \\n ; Output: An error occurred: incomplete input\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_393_database.db' and interacts with a table called 'students'. The table has the following columns: 'student_id' (INTEGER), 'name' (TEXT), 'major' (TEXT), and 'gpa' (REAL). The task is to prompt the user to input a student ID and then retrieve and print the record from the 'students' table that matches the given student ID. The input should be a single student ID, and the output should display the corresponding student's record. Ensure the connection to the database is properly closed after executing the query.
[Example Input & Output]
- Input: 104\n ; Output: (104, 'David Wilson', 'Engineering', 3.7)
- Input: \n ; Output: An error occurred: incomplete input
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_393_database.db' and interacts with a table called 'students'. The table has the following columns: 'student_id' (INTEGER), 'name' (TEXT), 'major' (TEXT), and 'gpa' (REAL). The task is to prompt the user to input a student ID and then retrieve and print the record from the 'students' table that matches the given student ID. The input should be a single student ID, and the output should display the corresponding student's record. Ensure the connection to the database is properly closed after executing the query.
[Example Input & Output]
- Input: 104\n ; Output: (104, 'David Wilson', 'Engineering', 3.7)
- Input: \n ; Output: An error occurred: incomplete input
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_student_record(student_id):
try:
# Establish a connection to the SQLite database
conn = sqlite3.connect('program_393_database.db')
cursor = conn.cursor()
# Prepare a SQL query to select all columns from the students table where student_id matches the provided parameter
query = "SELECT * FROM students WHERE student_id = ?"
# Execute the query
cursor.execute(query, (student_id,))
# Fetch the result
result = cursor.fetchone()
# Print the result if found
if result:
print("Student Record Found:")
for column, value in zip(cursor.description, result):
print(f"{column[0]}: {value}")
else:
print("No record found.")
except sqlite3.Error as e:
print(f"An error occurred: {e}")
finally:
# Close the database connection
if conn:
conn.close()
# Prompt the user to input a student ID
student_id = input("Enter the student ID: ")
# Call the get_student_record function with the inputted student ID
get_student_record(student_id)
|
program_382
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_382_database.db' and queries a table called 'users'. The table contains columns: user_id, username, email, bio, age, and country. The task is to query this table based on user inputs. Specifically, the script should prompt the user for three inputs: a minimum age, a country, and a keyword to search within the bio column. Use these inputs to construct a SQL query that selects all users where the age is greater than or equal to the specified minimum age, or the country matches the input, or the bio contains the keyword. Execute this query and print the results directly. Ensure the database connection is properly closed after the operation.\n\n[Example Input & Output]\n- Input: 22\\nAustralia\\nGamer\\n ; Output: (1, 'user1', '[email protected]', 'Foodie who loves to travel.', 25, 'USA')\\n(2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\\n(3, 'user3', '[email protected]', 'Photographer and adventurer.', 22, 'Canada')\\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')\\n(8, 'user8', '[email protected]', 'Bookworm and aspiring author.', 24, 'India')\n- Input: 26\\nMexico\\nsongwriter\\n ; Output: (2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_382_database.db' and queries a table called 'users'. The table contains columns: user_id, username, email, bio, age, and country. The task is to query this table based on user inputs. Specifically, the script should prompt the user for three inputs: a minimum age, a country, and a keyword to search within the bio column. Use these inputs to construct a SQL query that selects all users where the age is greater than or equal to the specified minimum age, or the country matches the input, or the bio contains the keyword. Execute this query and print the results directly. Ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: 22\nAustralia\nGamer\n ; Output: (1, 'user1', '[email protected]', 'Foodie who loves to travel.', 25, 'USA')\n(2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\n(3, 'user3', '[email protected]', 'Photographer and adventurer.', 22, 'Canada')\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')\n(8, 'user8', '[email protected]', 'Bookworm and aspiring author.', 24, 'India')
- Input: 26\nMexico\nsongwriter\n ; Output: (2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_382_database.db' and queries a table called 'users'. The table contains columns: user_id, username, email, bio, age, and country. The task is to query this table based on user inputs. Specifically, the script should prompt the user for three inputs: a minimum age, a country, and a keyword to search within the bio column. Use these inputs to construct a SQL query that selects all users where the age is greater than or equal to the specified minimum age, or the country matches the input, or the bio contains the keyword. Execute this query and print the results directly. Ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: 22\nAustralia\nGamer\n ; Output: (1, 'user1', '[email protected]', 'Foodie who loves to travel.', 25, 'USA')\n(2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\n(3, 'user3', '[email protected]', 'Photographer and adventurer.', 22, 'Canada')\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')\n(8, 'user8', '[email protected]', 'Bookworm and aspiring author.', 24, 'India')
- Input: 26\nMexico\nsongwriter\n ; Output: (2, 'user2', '[email protected]', 'Tech enthusiast and blogger.', 30, 'UK')\n(4, 'user4', '[email protected]', 'Gamer. Coffee lover.', 28, 'Australia')\n(5, 'user5', '[email protected]', 'Nature lover and hiker.', 27, 'New Zealand')\n(6, 'user6', '[email protected]', 'Fitness coach and health blogger.', 35, 'USA')\n(7, 'user7', '[email protected]', 'Musician and songwriter.', 31, 'Ireland')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to {db_file}')
except Error as e:
print(e)
return conn
def execute_query(conn, query, params=None):
cur = conn.cursor()
try:
if params:
cur.execute(query, params)
else:
cur.execute(query)
conn.commit()
return cur.fetchall()
except Error as e:
print(e)
finally:
cur.close()
def fetch_results(conn, min_age, country, keyword):
query = """
SELECT *
FROM users
WHERE age >= ? AND country = ? AND name LIKE ?
"""
params = (min_age, country, f'%{keyword}%')
results = execute_query(conn, query, params)
return results
def main():
db_file = 'program_382_database.db'
conn = create_connection(db_file)
if conn is not None:
try:
min_age = int(input("Enter minimum age: "))
country = input("Enter country: ")
keyword = input("Enter keyword: ")
results = fetch_results(conn, min_age, country, keyword)
if results:
for row in results:
print(row)
else:
print("No matching records found.")
except ValueError:
print("Invalid input for age. Please enter a valid integer.")
except Error as e:
print(e)
else:
print("Error! Cannot establish a database connection.")
conn.close()
if __name__ == '__main__':
main()
|
program_1
|
[
{
"content": "[Problem]\nThe database is stored in a file named 'program_1_database.db' and contains a table called 'orders'. This table has four columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to write a code snippet that connects to this database and retrieves all records from the 'orders' table where the 'customer_name' matches a user-provided input. The input should be a single string representing the customer's name. After executing the query, the code should print each row of the result. The connection to the database should be closed after the operation is complete.\n\n[Example Input & Output]\n- Input: Bob\\n ; Output: (102, 'Bob', 'Monitor', 150.0)\n- Input: Hannah\\n ; Output: (108, 'Hannah', 'Printer', 250.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is stored in a file named 'program_1_database.db' and contains a table called 'orders'. This table has four columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to write a code snippet that connects to this database and retrieves all records from the 'orders' table where the 'customer_name' matches a user-provided input. The input should be a single string representing the customer's name. After executing the query, the code should print each row of the result. The connection to the database should be closed after the operation is complete.
[Example Input & Output]
- Input: Bob\n ; Output: (102, 'Bob', 'Monitor', 150.0)
- Input: Hannah\n ; Output: (108, 'Hannah', 'Printer', 250.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is stored in a file named 'program_1_database.db' and contains a table called 'orders'. This table has four columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to write a code snippet that connects to this database and retrieves all records from the 'orders' table where the 'customer_name' matches a user-provided input. The input should be a single string representing the customer's name. After executing the query, the code should print each row of the result. The connection to the database should be closed after the operation is complete.
[Example Input & Output]
- Input: Bob\n ; Output: (102, 'Bob', 'Monitor', 150.0)
- Input: Hannah\n ; Output: (108, 'Hannah', 'Printer', 250.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def retrieve_orders_by_customer_name():
# Retrieve customer name from user input
customer_name = input("Enter the customer's name: ")
# Connect to the SQLite database
conn = sqlite3.connect('program_1_database.db')
cursor = conn.cursor()
# Execute the SQL query to retrieve orders based on customer name
cursor.execute("SELECT * FROM orders WHERE customer_name = ?", (customer_name,))
# Fetch all the results
results = cursor.fetchall()
# Print the results
if results:
print("Orders for customer:", customer_name)
for order in results:
print(order)
else:
print("No orders found for customer:", customer_name)
# Close the database connection
conn.close()
# Call the function to execute the code
retrieve_orders_by_customer_name()
|
program_372
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_372_database.db' and queries a table called 'patients'. The table contains columns: patient_id, name, age, diagnosis, treatment, and doctor. The task is to take user inputs for the doctor's name, a minimum and maximum age range, a search field (which can be name, diagnosis, or treatment), a search value, a column to order the results by (which can be patient_id, name, or age), and the order direction (ASC or DESC). Use these inputs to construct and execute a SQL query that retrieves all patient records matching the criteria, and print the results.\n\n[Example Input & Output]\n- Input: Dr. Moore\\n30\\n50\\ntreatment\\nPain\\nname\\nDESC\\n ; Output: [(7, 'James Wilson', 38, 'Migraine', 'Pain Relievers', 'Dr. Moore')]\n- Input: Dr. Johnson\\n30\\n40\\ntreatment\\nInhaler\\nage\\nASC\\n ; Output: [(4, 'Emily Davis', 34, 'Asthma', 'Inhaler', 'Dr. Johnson')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_372_database.db' and queries a table called 'patients'. The table contains columns: patient_id, name, age, diagnosis, treatment, and doctor. The task is to take user inputs for the doctor's name, a minimum and maximum age range, a search field (which can be name, diagnosis, or treatment), a search value, a column to order the results by (which can be patient_id, name, or age), and the order direction (ASC or DESC). Use these inputs to construct and execute a SQL query that retrieves all patient records matching the criteria, and print the results.
[Example Input & Output]
- Input: Dr. Moore\n30\n50\ntreatment\nPain\nname\nDESC\n ; Output: [(7, 'James Wilson', 38, 'Migraine', 'Pain Relievers', 'Dr. Moore')]
- Input: Dr. Johnson\n30\n40\ntreatment\nInhaler\nage\nASC\n ; Output: [(4, 'Emily Davis', 34, 'Asthma', 'Inhaler', 'Dr. Johnson')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_372_database.db' and queries a table called 'patients'. The table contains columns: patient_id, name, age, diagnosis, treatment, and doctor. The task is to take user inputs for the doctor's name, a minimum and maximum age range, a search field (which can be name, diagnosis, or treatment), a search value, a column to order the results by (which can be patient_id, name, or age), and the order direction (ASC or DESC). Use these inputs to construct and execute a SQL query that retrieves all patient records matching the criteria, and print the results.
[Example Input & Output]
- Input: Dr. Moore\n30\n50\ntreatment\nPain\nname\nDESC\n ; Output: [(7, 'James Wilson', 38, 'Migraine', 'Pain Relievers', 'Dr. Moore')]
- Input: Dr. Johnson\n30\n40\ntreatment\nInhaler\nage\nASC\n ; Output: [(4, 'Emily Davis', 34, 'Asthma', 'Inhaler', 'Dr. Johnson')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def query_patients():
# Connect to the SQLite database
conn = sqlite3.connect('program_372_database.db')
cursor = conn.cursor()
# Prompt user for input values
doctor_name = input("Enter doctor's name: ")
min_age = int(input("Enter minimum age: "))
max_age = int(input("Enter maximum age: "))
search_field = input("Enter search field (name, diagnosis, treatment): ")
search_value = input("Enter search value: ")
order_column = input("Enter order column (patient_id, name, age): ")
order_direction = input("Enter order direction (ASC or DESC): ")
# Construct parameterized SQL query
query = """
SELECT *
FROM patients
WHERE doctor_name = ? AND age BETWEEN ? AND ?
AND ? LIKE ?
ORDER BY ? ASC;
"""
# Execute the query with parameterized values
cursor.execute(query, (doctor_name, min_age, max_age, search_field, f'%{search_value}%', order_column))
# Fetch all results
results = cursor.fetchall()
# Print the results
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function to execute the query
query_patients()
|
program_301
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_301_database.db' and queries a table called 'marketing_campaigns'. The table contains columns: id, campaign_name, impressions, clicks, and budget. The task is to prompt the user to input a campaign name and then retrieve and print all records from the 'marketing_campaigns' table where the campaign_name matches the user input. If no records are found, print a message indicating no matching campaign was found. Ensure the database connection is properly closed after executing the query.\n\n[Example Input & Output]\n- Input: springFever\\n ; Output: No matching campaign found.\n- Input: SpringSale\\n ; Output: No matching campaign found.\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_301_database.db' and queries a table called 'marketing_campaigns'. The table contains columns: id, campaign_name, impressions, clicks, and budget. The task is to prompt the user to input a campaign name and then retrieve and print all records from the 'marketing_campaigns' table where the campaign_name matches the user input. If no records are found, print a message indicating no matching campaign was found. Ensure the database connection is properly closed after executing the query.
[Example Input & Output]
- Input: springFever\n ; Output: No matching campaign found.
- Input: SpringSale\n ; Output: No matching campaign found.
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_301_database.db' and queries a table called 'marketing_campaigns'. The table contains columns: id, campaign_name, impressions, clicks, and budget. The task is to prompt the user to input a campaign name and then retrieve and print all records from the 'marketing_campaigns' table where the campaign_name matches the user input. If no records are found, print a message indicating no matching campaign was found. Ensure the database connection is properly closed after executing the query.
[Example Input & Output]
- Input: springFever\n ; Output: No matching campaign found.
- Input: SpringSale\n ; Output: No matching campaign found.
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_301_database.db')
cursor = conn.cursor()
# Prompt the user to input a campaign name
campaign_name = input("Enter the campaign name: ")
# Search for the campaign name in the 'marketing_campaigns' table
cursor.execute("SELECT * FROM marketing_campaigns WHERE campaign_name = ?", (campaign_name,))
results = cursor.fetchall()
# Print any matching records
if results:
print("Matching campaigns:")
for row in results:
print(row)
else:
print("No matching campaign found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_170
|
[
{
"content": "[Problem]\nGiven a SQLite database file named 'program_170_database.db', there is a table called 'sales' with the following columns: order_id (INTEGER), customer_name (TEXT), item (TEXT), and amount (REAL). The task is to write a Python script that connects to this database and retrieves all orders for a specific customer. The script should prompt the user to input a customer name and then execute a query to fetch and print all records from the 'sales' table where the customer_name matches the input. Ensure the script closes the database connection after retrieving and displaying the results.\n\n[Example Input & Output]\n- Input: Alice\\n ; Output: (1, 'Alice', 'Laptop', 1200.0)\n- Input: Heidi\\n ; Output: (8, 'Heidi', 'Keyboard', 75.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Given a SQLite database file named 'program_170_database.db', there is a table called 'sales' with the following columns: order_id (INTEGER), customer_name (TEXT), item (TEXT), and amount (REAL). The task is to write a Python script that connects to this database and retrieves all orders for a specific customer. The script should prompt the user to input a customer name and then execute a query to fetch and print all records from the 'sales' table where the customer_name matches the input. Ensure the script closes the database connection after retrieving and displaying the results.
[Example Input & Output]
- Input: Alice\n ; Output: (1, 'Alice', 'Laptop', 1200.0)
- Input: Heidi\n ; Output: (8, 'Heidi', 'Keyboard', 75.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Given a SQLite database file named 'program_170_database.db', there is a table called 'sales' with the following columns: order_id (INTEGER), customer_name (TEXT), item (TEXT), and amount (REAL). The task is to write a Python script that connects to this database and retrieves all orders for a specific customer. The script should prompt the user to input a customer name and then execute a query to fetch and print all records from the 'sales' table where the customer_name matches the input. Ensure the script closes the database connection after retrieving and displaying the results.
[Example Input & Output]
- Input: Alice\n ; Output: (1, 'Alice', 'Laptop', 1200.0)
- Input: Heidi\n ; Output: (8, 'Heidi', 'Keyboard', 75.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def fetch_customer_orders():
# Connect to the SQLite database
conn = sqlite3.connect('program_170_database.db')
cursor = conn.cursor()
# Prompt the user to input a customer name
customer_name = input("Enter customer name: ")
# Construct the SQL query to fetch orders for the specified customer
query = "SELECT order_id, customer_name, item, amount FROM sales WHERE customer_name = ?"
# Execute the query with the user input
cursor.execute(query, (customer_name,))
# Fetch all the results
results = cursor.fetchall()
# Print the results
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function to execute the task
fetch_customer_orders()
|
program_370
|
[
{
"content": "[Problem]\nYou have a database file named 'program_370_database.db' which contains a table called 'customer_info'. This table has the following columns: customer_id, first_name, last_name, email, balance, and membership_level. Your task is to write a code snippet that connects to this database and retrieves customer records based on user input. The user will provide four inputs: a minimum account balance, a maximum account balance, a bonus percentage, and a membership level. The code should calculate an effective balance range by adjusting the minimum and maximum balances with the bonus percentage. Then, it should construct and execute a SQL query to select all customers whose balance falls within this effective range or whose membership level matches the user-provided level. Finally, the code should print out the details of the customers that meet these criteria.\n\n[Example Input & Output]\n- Input: 100\\n900\\n0.08\\nGold\\n ; Output: (1, 'John', 'Doe', '[email protected]', 150.0, 'Gold')\\n(2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')\n- Input: 200\\n1000\\n0.05\\nSilver\\n ; Output: (2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\\n(3, 'Emily', 'Jones', '[email protected]', 995.0, 'Silver')\\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_370_database.db' which contains a table called 'customer_info'. This table has the following columns: customer_id, first_name, last_name, email, balance, and membership_level. Your task is to write a code snippet that connects to this database and retrieves customer records based on user input. The user will provide four inputs: a minimum account balance, a maximum account balance, a bonus percentage, and a membership level. The code should calculate an effective balance range by adjusting the minimum and maximum balances with the bonus percentage. Then, it should construct and execute a SQL query to select all customers whose balance falls within this effective range or whose membership level matches the user-provided level. Finally, the code should print out the details of the customers that meet these criteria.
[Example Input & Output]
- Input: 100\n900\n0.08\nGold\n ; Output: (1, 'John', 'Doe', '[email protected]', 150.0, 'Gold')\n(2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')
- Input: 200\n1000\n0.05\nSilver\n ; Output: (2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\n(3, 'Emily', 'Jones', '[email protected]', 995.0, 'Silver')\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_370_database.db' which contains a table called 'customer_info'. This table has the following columns: customer_id, first_name, last_name, email, balance, and membership_level. Your task is to write a code snippet that connects to this database and retrieves customer records based on user input. The user will provide four inputs: a minimum account balance, a maximum account balance, a bonus percentage, and a membership level. The code should calculate an effective balance range by adjusting the minimum and maximum balances with the bonus percentage. Then, it should construct and execute a SQL query to select all customers whose balance falls within this effective range or whose membership level matches the user-provided level. Finally, the code should print out the details of the customers that meet these criteria.
[Example Input & Output]
- Input: 100\n900\n0.08\nGold\n ; Output: (1, 'John', 'Doe', '[email protected]', 150.0, 'Gold')\n(2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')
- Input: 200\n1000\n0.05\nSilver\n ; Output: (2, 'Jane', 'Smith', '[email protected]', 230.5, 'Platinum')\n(3, 'Emily', 'Jones', '[email protected]', 995.0, 'Silver')\n(4, 'Michael', 'Brown', '[email protected]', 780.0, 'Gold')\n(7, 'Anna', 'Taylor', '[email protected]', 300.0, 'Silver')\n(8, 'David', 'Anderson', '[email protected]', 450.0, 'Gold')\n(9, 'Laura', 'Thomas', '[email protected]', 650.0, 'Silver')\n(10, 'James', 'White', '[email protected]', 500.0, 'Gold')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import os
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_370_database.db')
cursor = conn.cursor()
# Retrieve sensitive information from environment variables
secret_key = os.getenv('SECRET_KEY')
password = os.getenv('PASSWORD')
# Prompt the user for input to filter customer data
min_balance = float(input("Enter minimum account balance: "))
bonus_percentage = float(input("Enter bonus percentage: "))
membership_level = input("Enter membership level (e.g., 'Gold', 'Silver'): ")
# Construct and execute the SQL query
query = """
SELECT *
FROM customers
WHERE account_balance >= ? AND bonus_percentage >= ? AND membership_level = ?
"""
cursor.execute(query, (min_balance, bonus_percentage, membership_level))
# Fetch and print customer details
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_345
|
[
{
"content": "[Problem]\nYou have a database named 'program_345_database.db' with a table called 'papers'. This table contains columns: paper_id, title, author, year_published, category, and abstract. Your task is to write a script that connects to this database and retrieves all records from the 'papers' table where the year_published matches a user-provided year and the category matches a user-provided category. The script should prompt the user for these two inputs: the publication year and the research category. After executing the query, the script should print out the results.\n\n[Example Input & Output]\n- Input: 2021\\nRobotics\\n ; Output: (9, 'Robotics in Manufacturing', 'Dr. Ian Black', 2021, 'Robotics', 'The role of robotics in ...')\n- Input: 2022\\nData Science\\n ; Output: (10, 'Data Privacy in the Age of Big Data', 'Dr. Julia White', 2022, 'Data Science', 'Challenges and solutions ...')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database named 'program_345_database.db' with a table called 'papers'. This table contains columns: paper_id, title, author, year_published, category, and abstract. Your task is to write a script that connects to this database and retrieves all records from the 'papers' table where the year_published matches a user-provided year and the category matches a user-provided category. The script should prompt the user for these two inputs: the publication year and the research category. After executing the query, the script should print out the results.
[Example Input & Output]
- Input: 2021\nRobotics\n ; Output: (9, 'Robotics in Manufacturing', 'Dr. Ian Black', 2021, 'Robotics', 'The role of robotics in ...')
- Input: 2022\nData Science\n ; Output: (10, 'Data Privacy in the Age of Big Data', 'Dr. Julia White', 2022, 'Data Science', 'Challenges and solutions ...')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database named 'program_345_database.db' with a table called 'papers'. This table contains columns: paper_id, title, author, year_published, category, and abstract. Your task is to write a script that connects to this database and retrieves all records from the 'papers' table where the year_published matches a user-provided year and the category matches a user-provided category. The script should prompt the user for these two inputs: the publication year and the research category. After executing the query, the script should print out the results.
[Example Input & Output]
- Input: 2021\nRobotics\n ; Output: (9, 'Robotics in Manufacturing', 'Dr. Ian Black', 2021, 'Robotics', 'The role of robotics in ...')
- Input: 2022\nData Science\n ; Output: (10, 'Data Privacy in the Age of Big Data', 'Dr. Julia White', 2022, 'Data Science', 'Challenges and solutions ...')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_user_input():
try:
publication_year = int(input("Enter the publication year: "))
research_category = input("Enter the research category: ")
return publication_year, research_category
except ValueError:
print("Invalid input for publication year. Please enter a valid integer.")
return None, None
def execute_query(conn, publication_year, research_category):
cursor = conn.cursor()
query = "SELECT * FROM papers WHERE publication_year = ? AND research_category = ?"
cursor.execute(query, (publication_year, research_category))
results = cursor.fetchall()
if results:
print("Papers found:")
for row in results:
print(row)
else:
print("No papers found for the given publication year and research category.")
def main():
conn = sqlite3.connect('program_345_database.db')
publication_year, research_category = get_user_input()
if publication_year is not None and research_category is not None:
execute_query(conn, publication_year, research_category)
conn.close()
if __name__ == "__main__":
main()
|
program_31
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_31_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'price'. The task is to prompt the user to input an item name and then search for this item in the 'inventory' table, printing out any matching records. The input should be a single string representing the item name to search for. Ensure the script executes the SQL query to retrieve and display the results based on the user's input.\n\n[Example Input & Output]\n- Input: Tablet\\n ; Output: (101, 'Tablet', 'Electronics', 300.0)\n- Input: Pen\\n ; Output: (108, 'Pen', 'Stationery', 1.5)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_31_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'price'. The task is to prompt the user to input an item name and then search for this item in the 'inventory' table, printing out any matching records. The input should be a single string representing the item name to search for. Ensure the script executes the SQL query to retrieve and display the results based on the user's input.
[Example Input & Output]
- Input: Tablet\n ; Output: (101, 'Tablet', 'Electronics', 300.0)
- Input: Pen\n ; Output: (108, 'Pen', 'Stationery', 1.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_31_database.db' and interacts with a table called 'inventory'. The table has columns named 'item_id', 'item_name', 'item_type', and 'price'. The task is to prompt the user to input an item name and then search for this item in the 'inventory' table, printing out any matching records. The input should be a single string representing the item name to search for. Ensure the script executes the SQL query to retrieve and display the results based on the user's input.
[Example Input & Output]
- Input: Tablet\n ; Output: (101, 'Tablet', 'Electronics', 300.0)
- Input: Pen\n ; Output: (108, 'Pen', 'Stationery', 1.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_inventory():
# Connect to the SQLite database
conn = sqlite3.connect('program_31_database.db')
cursor = conn.cursor()
# Prompt the user to enter an item name
item_name = input("Enter the item name to search for: ")
# Construct and execute the SQL query to search for partial matches
query = "SELECT * FROM inventory WHERE item_name LIKE ?"
cursor.execute(query, ('%' + item_name + '%',))
# Fetch and print all matching records
results = cursor.fetchall()
if results:
print("Matching items:")
for row in results:
print(row)
else:
print("No matching items found.")
# Close the database connection
cursor.close()
conn.close()
# Call the function to perform the search
search_inventory()
|
program_384
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_384_database.db' which contains a table called 'devices'. This table has columns named 'device_id', 'name', 'status', 'temperature', and 'location'. The task is to query this table based on user inputs. Specifically, the script should prompt the user to input a minimum temperature, a maximum temperature, a location, and a device status. The script should then adjust the temperature range by adding 0.5 to both the minimum and maximum values. Using these inputs, construct a SQL query to select all devices where the temperature is within the adjusted range or the location matches the input, and the status matches the input. Finally, execute the query and print the results.\n\n[Example Input & Output]\n- Input: -10\\n0\\nGarage\\nInactive\\n ; Output: [(8, 'Garage Door Opener', 'Inactive', None, 'Garage')]\n- Input: 0\\n5\\nKitchen\\nActive\\n ; Output: [(4, 'Fire Alarm', 'Active', 0.0, 'Kitchen')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_384_database.db' which contains a table called 'devices'. This table has columns named 'device_id', 'name', 'status', 'temperature', and 'location'. The task is to query this table based on user inputs. Specifically, the script should prompt the user to input a minimum temperature, a maximum temperature, a location, and a device status. The script should then adjust the temperature range by adding 0.5 to both the minimum and maximum values. Using these inputs, construct a SQL query to select all devices where the temperature is within the adjusted range or the location matches the input, and the status matches the input. Finally, execute the query and print the results.
[Example Input & Output]
- Input: -10\n0\nGarage\nInactive\n ; Output: [(8, 'Garage Door Opener', 'Inactive', None, 'Garage')]
- Input: 0\n5\nKitchen\nActive\n ; Output: [(4, 'Fire Alarm', 'Active', 0.0, 'Kitchen')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_384_database.db' which contains a table called 'devices'. This table has columns named 'device_id', 'name', 'status', 'temperature', and 'location'. The task is to query this table based on user inputs. Specifically, the script should prompt the user to input a minimum temperature, a maximum temperature, a location, and a device status. The script should then adjust the temperature range by adding 0.5 to both the minimum and maximum values. Using these inputs, construct a SQL query to select all devices where the temperature is within the adjusted range or the location matches the input, and the status matches the input. Finally, execute the query and print the results.
[Example Input & Output]
- Input: -10\n0\nGarage\nInactive\n ; Output: [(8, 'Garage Door Opener', 'Inactive', None, 'Garage')]
- Input: 0\n5\nKitchen\nActive\n ; Output: [(4, 'Fire Alarm', 'Active', 0.0, 'Kitchen')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_384_database.db')
cursor = conn.cursor()
# Prompt the user for input
min_temp = float(input("Enter minimum temperature: "))
max_temp = float(input("Enter maximum temperature: "))
location = input("Enter location: ")
status = input("Enter status: ")
# Adjust the temperature range
adjusted_min_temp = min_temp + 0.5
adjusted_max_temp = max_temp + 0.5
# Construct the SQL query
query = """
SELECT device_id, name, status, temperature, location
FROM devices
WHERE (temperature BETWEEN ? AND ?) OR (location = ? AND status = ?)
"""
# Execute the query
cursor.execute(query, (adjusted_min_temp, adjusted_max_temp, location, status))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
|
program_34
|
[
{
"content": "[Problem]\nCreate a script that connects to an SQLite database named 'program_34_database.db' and queries a table called 'products'. The 'products' table contains columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to prompt the user to input a search term, which will be used to find and print all rows from the 'products' table where the 'name' column matches the input. The input should be a single string representing the product name to search for.\n\n[Example Input & Output]\n- Input: Microwave\\n ; Output: (10, 'Microwave', 'Home Appliances', 120.0)\n- Input: Tablet\\n ; Output: (5, 'Tablet', 'Electronics', 400.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a script that connects to an SQLite database named 'program_34_database.db' and queries a table called 'products'. The 'products' table contains columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to prompt the user to input a search term, which will be used to find and print all rows from the 'products' table where the 'name' column matches the input. The input should be a single string representing the product name to search for.
[Example Input & Output]
- Input: Microwave\n ; Output: (10, 'Microwave', 'Home Appliances', 120.0)
- Input: Tablet\n ; Output: (5, 'Tablet', 'Electronics', 400.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a script that connects to an SQLite database named 'program_34_database.db' and queries a table called 'products'. The 'products' table contains columns: 'id' (INTEGER), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to prompt the user to input a search term, which will be used to find and print all rows from the 'products' table where the 'name' column matches the input. The input should be a single string representing the product name to search for.
[Example Input & Output]
- Input: Microwave\n ; Output: (10, 'Microwave', 'Home Appliances', 120.0)
- Input: Tablet\n ; Output: (5, 'Tablet', 'Electronics', 400.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_product():
# Connect to the SQLite database
conn = sqlite3.connect('program_34_database.db')
cursor = conn.cursor()
# Prompt the user to enter a product name
product_name = input("Enter the product name to search for: ")
# Construct and execute the SQL query
query = "SELECT * FROM products WHERE name = ?"
cursor.execute(query, (product_name,))
# Fetch and print all results
results = cursor.fetchall()
if results:
print("Product found:")
for row in results:
print(row)
else:
print("No product found with the given name.")
# Close the database connection
conn.close()
# Call the function to perform the search
search_product()
|
program_215
|
[
{
"content": "[Problem]\nThe database is set up for a social media application and contains a table named 'users' with the following columns: user_id (INTEGER), username (TEXT), bio (TEXT), age (INTEGER), and friends_count (INTEGER). The task is to connect to this database, which is stored in a file named 'program_215_database.db', and execute a query to retrieve users based on certain criteria. Specifically, the query should filter users whose friends_count is between a specified range and whose age matches a given preference, or whose bio contains a specific keyword. The inputs required for this task are four: a minimum number of friends, a maximum number of friends, an age preference, and a keyword to search within the bio. The query should adjust the friends_count range by subtracting 10 from the minimum and adding 10 to the maximum before executing the search. Finally, the results should be printed out.\n\n[Example Input & Output]\n- Input: 40\\n100\\n29\\nLoves\\n ; Output: (1, 'john_doe', 'Loves coding', 29, 150)\\n(6, 'diana_prince', 'Loves art and history', 28, 300)\n- Input: 0\\n80\\n25\\nAdventurous\\n ; Output: (3, 'alice_wonder', 'Adventurous writer', 25, 180)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is set up for a social media application and contains a table named 'users' with the following columns: user_id (INTEGER), username (TEXT), bio (TEXT), age (INTEGER), and friends_count (INTEGER). The task is to connect to this database, which is stored in a file named 'program_215_database.db', and execute a query to retrieve users based on certain criteria. Specifically, the query should filter users whose friends_count is between a specified range and whose age matches a given preference, or whose bio contains a specific keyword. The inputs required for this task are four: a minimum number of friends, a maximum number of friends, an age preference, and a keyword to search within the bio. The query should adjust the friends_count range by subtracting 10 from the minimum and adding 10 to the maximum before executing the search. Finally, the results should be printed out.
[Example Input & Output]
- Input: 40\n100\n29\nLoves\n ; Output: (1, 'john_doe', 'Loves coding', 29, 150)\n(6, 'diana_prince', 'Loves art and history', 28, 300)
- Input: 0\n80\n25\nAdventurous\n ; Output: (3, 'alice_wonder', 'Adventurous writer', 25, 180)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is set up for a social media application and contains a table named 'users' with the following columns: user_id (INTEGER), username (TEXT), bio (TEXT), age (INTEGER), and friends_count (INTEGER). The task is to connect to this database, which is stored in a file named 'program_215_database.db', and execute a query to retrieve users based on certain criteria. Specifically, the query should filter users whose friends_count is between a specified range and whose age matches a given preference, or whose bio contains a specific keyword. The inputs required for this task are four: a minimum number of friends, a maximum number of friends, an age preference, and a keyword to search within the bio. The query should adjust the friends_count range by subtracting 10 from the minimum and adding 10 to the maximum before executing the search. Finally, the results should be printed out.
[Example Input & Output]
- Input: 40\n100\n29\nLoves\n ; Output: (1, 'john_doe', 'Loves coding', 29, 150)\n(6, 'diana_prince', 'Loves art and history', 28, 300)
- Input: 0\n80\n25\nAdventurous\n ; Output: (3, 'alice_wonder', 'Adventurous writer', 25, 180)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_users(min_friends, max_friends, age_preference, keyword):
# Adjust min_friends and max_friends
min_friends -= 10
max_friends += 10
# Connect to the SQLite database
conn = sqlite3.connect('program_215_database.db')
# Construct the SQL query
query = """
SELECT user_id, username, bio, age, friends_count
FROM users
WHERE friends_count BETWEEN ? AND ?
AND age = ?
AND bio LIKE ?
"""
# Execute the query
cursor = conn.execute(query, (min_friends, max_friends, age_preference, f"%{keyword}%"))
# Fetch all results
results = cursor.fetchall()
# Print each result
for result in results:
print(result)
# Close the database connection
conn.close()
# Example usage
search_users(5, 15, 25, "Python")
|
program_208
|
[
{
"content": "[Problem]\nCreate a script that connects to a SQLite database named 'program_208_database.db' and queries a table called 'listings'. The table has columns: 'id' (INTEGER), 'title' (TEXT), 'location' (TEXT), and 'price' (REAL). The task is to prompt the user to input the title of a listing and then retrieve and print all records from the 'listings' table that match the given title. Ensure the script fetches and displays the results correctly.\n\n[Example Input & Output]\n- Input: Mountain Retreat\\n ; Output: (5, 'Mountain Retreat', 'Aspen', 2000000.0)\n- Input: Cozy Cottage\\n ; Output: (2, 'Cozy Cottage', 'Portland', 300000.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a script that connects to a SQLite database named 'program_208_database.db' and queries a table called 'listings'. The table has columns: 'id' (INTEGER), 'title' (TEXT), 'location' (TEXT), and 'price' (REAL). The task is to prompt the user to input the title of a listing and then retrieve and print all records from the 'listings' table that match the given title. Ensure the script fetches and displays the results correctly.
[Example Input & Output]
- Input: Mountain Retreat\n ; Output: (5, 'Mountain Retreat', 'Aspen', 2000000.0)
- Input: Cozy Cottage\n ; Output: (2, 'Cozy Cottage', 'Portland', 300000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a script that connects to a SQLite database named 'program_208_database.db' and queries a table called 'listings'. The table has columns: 'id' (INTEGER), 'title' (TEXT), 'location' (TEXT), and 'price' (REAL). The task is to prompt the user to input the title of a listing and then retrieve and print all records from the 'listings' table that match the given title. Ensure the script fetches and displays the results correctly.
[Example Input & Output]
- Input: Mountain Retreat\n ; Output: (5, 'Mountain Retreat', 'Aspen', 2000000.0)
- Input: Cozy Cottage\n ; Output: (2, 'Cozy Cottage', 'Portland', 300000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_208_database.db')
cursor = conn.cursor()
# Prompt the user for the title of the listing
title = input("Enter the title of the listing: ")
# Execute the SQL query to select all records with the input title
cursor.execute("SELECT * FROM listings WHERE title=?", (title,))
# Fetch and print the matching records
records = cursor.fetchall()
for record in records:
print(record)
# Close the database connection
conn.close()
|
program_172
|
[
{
"content": "[Problem]\nYou have a database file named 'program_172_database.db' which contains a table called 'population'. This table has four columns: 'id' (an integer), 'city' (a text field), 'state' (a text field), and 'population' (an integer). Your task is to write a code snippet that connects to this database and retrieves all records from the 'population' table where the population is greater than a user-specified threshold and the state matches a user-specified abbreviation. The code should take two inputs from the user: the population threshold and the state abbreviation. After executing the query, the code should print the results. Remember to close the database connection after retrieving the data.\n\n[Example Input & Output]\n- Input: 2500000\\nTX\\n ; Output: []\n- Input: 1400000\\nAZ\\n ; Output: [(5, 'Phoenix', 'AZ', 1681000)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_172_database.db' which contains a table called 'population'. This table has four columns: 'id' (an integer), 'city' (a text field), 'state' (a text field), and 'population' (an integer). Your task is to write a code snippet that connects to this database and retrieves all records from the 'population' table where the population is greater than a user-specified threshold and the state matches a user-specified abbreviation. The code should take two inputs from the user: the population threshold and the state abbreviation. After executing the query, the code should print the results. Remember to close the database connection after retrieving the data.
[Example Input & Output]
- Input: 2500000\nTX\n ; Output: []
- Input: 1400000\nAZ\n ; Output: [(5, 'Phoenix', 'AZ', 1681000)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_172_database.db' which contains a table called 'population'. This table has four columns: 'id' (an integer), 'city' (a text field), 'state' (a text field), and 'population' (an integer). Your task is to write a code snippet that connects to this database and retrieves all records from the 'population' table where the population is greater than a user-specified threshold and the state matches a user-specified abbreviation. The code should take two inputs from the user: the population threshold and the state abbreviation. After executing the query, the code should print the results. Remember to close the database connection after retrieving the data.
[Example Input & Output]
- Input: 2500000\nTX\n ; Output: []
- Input: 1400000\nAZ\n ; Output: [(5, 'Phoenix', 'AZ', 1681000)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_population_data(threshold, state):
# Connect to the SQLite database
conn = sqlite3.connect('program_172_database.db')
cursor = conn.cursor()
# Execute the SQL query
cursor.execute("SELECT * FROM population WHERE population > ? AND state = ?", (threshold, state))
# Fetch all the results
results = cursor.fetchall()
# Close the database connection
conn.close()
return results
# Prompt the user for input
threshold = int(input("Enter the population threshold: "))
state = input("Enter the state abbreviation: ")
# Call the function and store the results
results = get_population_data(threshold, state)
# Print the results
print(results)
|
program_473
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_473_database.db' and interacts with a table called 'users'. The 'users' table contains columns: 'user_id', 'username', 'email', and 'bio'. The task is to prompt the user for four inputs: a username to search for, an email domain to search within (like .com or .org), a column to order the results by (either 'username', 'email', or 'bio'), and the order type (either 'ASC' for ascending or 'DESC' for descending). Construct an SQL query using these inputs to select all columns from the 'users' table where the username matches the input or the email contains the specified domain, and order the results based on the user's input. Execute this query and print the results.\n\n[Example Input & Output]\n- Input: eve\\[email protected]\\nbio\\nDESC\\n ; Output: (4, 'dave', '[email protected]', 'Tech geek and part-time musician')\\n(3, 'carol', '[email protected]', 'Photography enthusiast and cat owner')\\n(1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')\\n(6, 'frank', '[email protected]', 'History buff and podcast producer')\\n(5, 'eve', '[email protected]', 'Fitness coach and nutrition expert')\\n(2, 'bob', '[email protected]', 'Coffee aficionado and daily blogger')\\n(7, 'grace', '[email protected]', 'Bookworm and aspiring novelist')\n- Input: alice\\[email protected]\\nemail\\nASC\\n ; Output: (1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_473_database.db' and interacts with a table called 'users'. The 'users' table contains columns: 'user_id', 'username', 'email', and 'bio'. The task is to prompt the user for four inputs: a username to search for, an email domain to search within (like .com or .org), a column to order the results by (either 'username', 'email', or 'bio'), and the order type (either 'ASC' for ascending or 'DESC' for descending). Construct an SQL query using these inputs to select all columns from the 'users' table where the username matches the input or the email contains the specified domain, and order the results based on the user's input. Execute this query and print the results.
[Example Input & Output]
- Input: eve\[email protected]\nbio\nDESC\n ; Output: (4, 'dave', '[email protected]', 'Tech geek and part-time musician')\n(3, 'carol', '[email protected]', 'Photography enthusiast and cat owner')\n(1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')\n(6, 'frank', '[email protected]', 'History buff and podcast producer')\n(5, 'eve', '[email protected]', 'Fitness coach and nutrition expert')\n(2, 'bob', '[email protected]', 'Coffee aficionado and daily blogger')\n(7, 'grace', '[email protected]', 'Bookworm and aspiring novelist')
- Input: alice\[email protected]\nemail\nASC\n ; Output: (1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_473_database.db' and interacts with a table called 'users'. The 'users' table contains columns: 'user_id', 'username', 'email', and 'bio'. The task is to prompt the user for four inputs: a username to search for, an email domain to search within (like .com or .org), a column to order the results by (either 'username', 'email', or 'bio'), and the order type (either 'ASC' for ascending or 'DESC' for descending). Construct an SQL query using these inputs to select all columns from the 'users' table where the username matches the input or the email contains the specified domain, and order the results based on the user's input. Execute this query and print the results.
[Example Input & Output]
- Input: eve\[email protected]\nbio\nDESC\n ; Output: (4, 'dave', '[email protected]', 'Tech geek and part-time musician')\n(3, 'carol', '[email protected]', 'Photography enthusiast and cat owner')\n(1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')\n(6, 'frank', '[email protected]', 'History buff and podcast producer')\n(5, 'eve', '[email protected]', 'Fitness coach and nutrition expert')\n(2, 'bob', '[email protected]', 'Coffee aficionado and daily blogger')\n(7, 'grace', '[email protected]', 'Bookworm and aspiring novelist')
- Input: alice\[email protected]\nemail\nASC\n ; Output: (1, 'alice', '[email protected]', 'Loves hiking and streaming indie games')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import os
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to the database {db_file}')
except Error as e:
print(e)
return conn
def select_users(conn, username=None, email_domain=None, column_name=None, order_type='ASC'):
query = "SELECT * FROM users"
params = []
if username:
query += f" WHERE username LIKE ?"
params.append(f'%{username}%')
if email_domain:
query += f" AND email LIKE ?"
params.append(f'%@{email_domain}%')
if column_name:
query += f" ORDER BY {column_name} {order_type}"
try:
cur = conn.cursor()
cur.execute(query, params)
rows = cur.fetchall()
return rows
except Error as e:
print(e)
return []
def main():
db_file = os.getenv('DATABASE_FILE', 'users.db')
conn = create_connection(db_file)
if conn is not None:
try:
# Example usage of select_users function
users = select_users(conn, username='john_doe', email_domain='example.com', column_name='email', order_type='DESC')
for user in users:
print(user)
finally:
conn.close()
else:
print("Error! Cannot establish a database connection.")
if __name__ == '__main__':
main()
|
program_261
|
[
{
"content": "[Problem]\nThe database is named 'program_261_database.db' and contains a table called 'tickets' with the following columns: event_id (INTEGER), event_name (TEXT), location (TEXT), and ticket_price (REAL). The task is to query this database to find all events that match a specific location and have ticket prices within a certain range after applying a discount. The inputs required are: a minimum ticket price, a maximum ticket price, a ticket discount percentage, and a desired event location. Use these inputs to adjust the ticket price range and retrieve the matching events from the database.\n\n[Example Input & Output]\n- Input: 50\\n300\\n0.10\\nSan Francisco\\n ; Output: [(5, 'Workshop E', 'San Francisco', 180.0)]\n- Input: 50\\n210\\n0.05\\nLas Vegas\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_261_database.db' and contains a table called 'tickets' with the following columns: event_id (INTEGER), event_name (TEXT), location (TEXT), and ticket_price (REAL). The task is to query this database to find all events that match a specific location and have ticket prices within a certain range after applying a discount. The inputs required are: a minimum ticket price, a maximum ticket price, a ticket discount percentage, and a desired event location. Use these inputs to adjust the ticket price range and retrieve the matching events from the database.
[Example Input & Output]
- Input: 50\n300\n0.10\nSan Francisco\n ; Output: [(5, 'Workshop E', 'San Francisco', 180.0)]
- Input: 50\n210\n0.05\nLas Vegas\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_261_database.db' and contains a table called 'tickets' with the following columns: event_id (INTEGER), event_name (TEXT), location (TEXT), and ticket_price (REAL). The task is to query this database to find all events that match a specific location and have ticket prices within a certain range after applying a discount. The inputs required are: a minimum ticket price, a maximum ticket price, a ticket discount percentage, and a desired event location. Use these inputs to adjust the ticket price range and retrieve the matching events from the database.
[Example Input & Output]
- Input: 50\n300\n0.10\nSan Francisco\n ; Output: [(5, 'Workshop E', 'San Francisco', 180.0)]
- Input: 50\n210\n0.05\nLas Vegas\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import os
import sqlite3
def get_sensitive_info():
secret_key = os.getenv('SECRET_KEY')
password = os.getenv('PASSWORD')
return secret_key, password
def calculate_adjusted_price_range(min_price, max_price, discount_percentage):
adjusted_min_price = min_price * (1 - discount_percentage / 100)
adjusted_max_price = max_price * (1 - discount_percentage / 100)
return adjusted_min_price, adjusted_max_price
def main():
if __name__ == "__main__":
# Retrieve sensitive information from environment variables
secret_key, password = get_sensitive_info()
# Take user input
min_price = float(input("Enter minimum ticket price: "))
max_price = float(input("Enter maximum ticket price: "))
discount_percentage = float(input("Enter discount percentage: "))
event_location = input("Enter event location: ")
# Calculate adjusted price range
adjusted_min_price, adjusted_max_price = calculate_adjusted_price_range(min_price, max_price, discount_percentage)
# Construct SQL query
query = """
SELECT event_id, event_name, location, ticket_price
FROM tickets
WHERE location = ? AND ticket_price BETWEEN ? AND ?
"""
# Connect to SQLite database
conn = sqlite3.connect('program_261_database.db')
cursor = conn.cursor()
# Execute query and fetch results
cursor.execute(query, (event_location, adjusted_min_price, adjusted_max_price))
results = cursor.fetchall()
# Print results
for result in results:
print(result)
# Close database connection
conn.close()
if __name__ == "__main__":
main()
|
program_341
|
[
{
"content": "[Problem]\nThe database is named 'program_341_database.db' and contains a table called 'player_stats'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'team' (TEXT), 'avg_score' (REAL), and 'position' (TEXT). The task is to query this table to find players based on specific criteria. The user will provide four inputs: a minimum average score, a maximum average score, a desired player position, and a team name to exclude from the results. The query should select all players whose average score is between the given minimum and maximum, who play in the specified position, and who are not part of the excluded team. The results should be printed out.\n\n[Example Input & Output]\n- Input: 17\\n23\\nForward\\nLions\\n ; Output: [(4, 'Jake Blues', 'Tigers', 17.4, 'Forward')]\n- Input: 15\\n19\\nGuard\\nLions\\n ; Output: [(2, 'Jane Smith', 'Tigers', 18.2, 'Guard'), (8, 'David Gray', 'Tigers', 16.1, 'Guard')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_341_database.db' and contains a table called 'player_stats'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'team' (TEXT), 'avg_score' (REAL), and 'position' (TEXT). The task is to query this table to find players based on specific criteria. The user will provide four inputs: a minimum average score, a maximum average score, a desired player position, and a team name to exclude from the results. The query should select all players whose average score is between the given minimum and maximum, who play in the specified position, and who are not part of the excluded team. The results should be printed out.
[Example Input & Output]
- Input: 17\n23\nForward\nLions\n ; Output: [(4, 'Jake Blues', 'Tigers', 17.4, 'Forward')]
- Input: 15\n19\nGuard\nLions\n ; Output: [(2, 'Jane Smith', 'Tigers', 18.2, 'Guard'), (8, 'David Gray', 'Tigers', 16.1, 'Guard')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_341_database.db' and contains a table called 'player_stats'. This table has the following columns: 'id' (INTEGER), 'name' (TEXT), 'team' (TEXT), 'avg_score' (REAL), and 'position' (TEXT). The task is to query this table to find players based on specific criteria. The user will provide four inputs: a minimum average score, a maximum average score, a desired player position, and a team name to exclude from the results. The query should select all players whose average score is between the given minimum and maximum, who play in the specified position, and who are not part of the excluded team. The results should be printed out.
[Example Input & Output]
- Input: 17\n23\nForward\nLions\n ; Output: [(4, 'Jake Blues', 'Tigers', 17.4, 'Forward')]
- Input: 15\n19\nGuard\nLions\n ; Output: [(2, 'Jane Smith', 'Tigers', 18.2, 'Guard'), (8, 'David Gray', 'Tigers', 16.1, 'Guard')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
import os
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to the {db_file} database')
except Error as e:
print(e)
return conn
def sanitize_input(input_data):
# Implement input sanitization logic here
# For example, using regular expressions to remove unwanted characters
sanitized_data = input_data.strip()
return sanitized_data
def get_player_statistics(conn, criteria):
cursor = conn.cursor()
# Sanitize user input
avg_score = sanitize_input(criteria.get('avg_score', ''))
position = sanitize_input(criteria.get('position', ''))
excluded_team = sanitize_input(criteria.get('excluded_team', ''))
query = """
SELECT player_id, name, position, avg_score, total_games
FROM players
WHERE avg_score > ? AND position = ? AND team != ?
"""
params = (avg_score, position, excluded_team)
cursor.execute(query, params)
rows = cursor.fetchall()
return rows
def main():
db_file = os.getenv('DATABASE_FILE', 'players.db')
conn = create_connection(db_file)
if conn is not None:
criteria = {
'avg_score': '90',
'position': 'Forward',
'excluded_team': 'Red Team'
}
statistics = get_player_statistics(conn, criteria)
for row in statistics:
print(row)
else:
print("Error! Cannot connect to the database.")
if __name__ == '__main__':
main()
|
program_8
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_8_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to write a script that prompts the user to input an item name and then searches for this item in the 'inventory' table by its name. The script should retrieve and print all the details of the item(s) that match the given name. The input should be a single string representing the item name to search for. Ensure the connection to the database is properly closed after the operation.\n\n[Example Input & Output]\n- Input: Apparatus\\n ; Output: (7, 'Apparatus', 'Gadgets', 120, 34.99)\n- Input: Whatchamacallit\\n ; Output: (4, 'Whatchamacallit', 'Gizmos', 200, 9.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_8_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to write a script that prompts the user to input an item name and then searches for this item in the 'inventory' table by its name. The script should retrieve and print all the details of the item(s) that match the given name. The input should be a single string representing the item name to search for. Ensure the connection to the database is properly closed after the operation.
[Example Input & Output]
- Input: Apparatus\n ; Output: (7, 'Apparatus', 'Gadgets', 120, 34.99)
- Input: Whatchamacallit\n ; Output: (4, 'Whatchamacallit', 'Gizmos', 200, 9.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_8_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to write a script that prompts the user to input an item name and then searches for this item in the 'inventory' table by its name. The script should retrieve and print all the details of the item(s) that match the given name. The input should be a single string representing the item name to search for. Ensure the connection to the database is properly closed after the operation.
[Example Input & Output]
- Input: Apparatus\n ; Output: (7, 'Apparatus', 'Gadgets', 120, 34.99)
- Input: Whatchamacallit\n ; Output: (4, 'Whatchamacallit', 'Gizmos', 200, 9.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import os
def get_secret_key():
# Retrieve secret key from environment variable
return os.getenv('SECRET_KEY')
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_8_database.db')
cursor = conn.cursor()
# Prompt the user to input an item name
item_name = input("Enter the item name to search for: ")
# Construct and execute the SQL query
query = "SELECT * FROM inventory WHERE item_name LIKE ?"
cursor.execute(query, (f"%{item_name}%",))
# Fetch and print the results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No items found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_247
|
[
{
"content": "[Problem]\nYou have a database named 'program_247_database.db' with a table called 'papers'. This table contains columns: id, title, author, year, field, and citations. Your task is to write a script that connects to this database and retrieves records from the 'papers' table based on user inputs. The script should prompt the user for four inputs: the start year of publication, the end year of publication, the minimum number of citations, and the research field. Using these inputs, construct a SQL query to select all records where the year is between the start year and end year, the field matches the input field, and the number of citations is greater than or equal to the input minimum citations. Execute this query and print the results. Close the database connection after retrieving and displaying the data.\n\n[Example Input & Output]\n- Input: 2018\\n2022\\n50\\nNanotechnology\\n ; Output: (7, 'Nanotechnology Frontiers', 'Grace Lee', 2019, 'Nanotechnology', 75)\n- Input: 2018\\n2022\\n50\\nCybersecurity\\n ; Output: (4, 'Cybersecurity Basics', 'David Brown', 2018, 'Cybersecurity', 90)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database named 'program_247_database.db' with a table called 'papers'. This table contains columns: id, title, author, year, field, and citations. Your task is to write a script that connects to this database and retrieves records from the 'papers' table based on user inputs. The script should prompt the user for four inputs: the start year of publication, the end year of publication, the minimum number of citations, and the research field. Using these inputs, construct a SQL query to select all records where the year is between the start year and end year, the field matches the input field, and the number of citations is greater than or equal to the input minimum citations. Execute this query and print the results. Close the database connection after retrieving and displaying the data.
[Example Input & Output]
- Input: 2018\n2022\n50\nNanotechnology\n ; Output: (7, 'Nanotechnology Frontiers', 'Grace Lee', 2019, 'Nanotechnology', 75)
- Input: 2018\n2022\n50\nCybersecurity\n ; Output: (4, 'Cybersecurity Basics', 'David Brown', 2018, 'Cybersecurity', 90)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database named 'program_247_database.db' with a table called 'papers'. This table contains columns: id, title, author, year, field, and citations. Your task is to write a script that connects to this database and retrieves records from the 'papers' table based on user inputs. The script should prompt the user for four inputs: the start year of publication, the end year of publication, the minimum number of citations, and the research field. Using these inputs, construct a SQL query to select all records where the year is between the start year and end year, the field matches the input field, and the number of citations is greater than or equal to the input minimum citations. Execute this query and print the results. Close the database connection after retrieving and displaying the data.
[Example Input & Output]
- Input: 2018\n2022\n50\nNanotechnology\n ; Output: (7, 'Nanotechnology Frontiers', 'Grace Lee', 2019, 'Nanotechnology', 75)
- Input: 2018\n2022\n50\nCybersecurity\n ; Output: (4, 'Cybersecurity Basics', 'David Brown', 2018, 'Cybersecurity', 90)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_247_database.db')
cursor = conn.cursor()
# Prompt user for input
start_year = int(input("Enter the start year: "))
end_year = int(input("Enter the end year: "))
min_citations = int(input("Enter the minimum number of citations: "))
research_field = input("Enter the research field: ")
# Construct the SQL query
query = """
SELECT title, author, year, citations
FROM papers
WHERE year BETWEEN ? AND ?
AND citations >= ?
AND research_field = ?
"""
# Execute the query with user inputs
cursor.execute(query, (start_year, end_year, min_citations, research_field))
# Fetch and print the results
results = cursor.fetchall()
for paper in results:
print(f"Title: {paper[0]}, Author: {paper[1]}, Year: {paper[2]}, Citations: {paper[3]}")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_453
|
[
{
"content": "[Problem]\nWe have a database file named 'program_453_database.db' which contains a table called 'sensor_data'. This table has the following columns: 'device_id' (TEXT), 'timestamp' (TEXT), 'temperature' (REAL), and 'humidity' (REAL). The task is to write a code snippet that queries this database to retrieve sensor data based on user input. The user should provide the 'device_id', a starting 'timestamp', and an ending 'timestamp' to filter the data. Additionally, the user should specify a column to sort the results by, which can be either 'temperature', 'humidity', or 'timestamp', and also indicate the sort direction, either 'ASC' for ascending or 'DESC' for descending. The code should execute the query with these inputs and print the results.\n\n[Example Input & Output]\n- Input: sensor_1\\n2023-10-01 09:30:00\\n2023-10-01 10:30:00\\nhumidity\\nDESC\\n ; Output: ('sensor_1', '2023-10-01 10:00:00', 22.5, 45.0)\n- Input: sensor_7\\n2023-10-01 15:00:00\\n2023-10-01 17:00:00\\ntemperature\\nASC\\n ; Output: ('sensor_7', '2023-10-01 16:00:00', 23.9, 40.5)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_453_database.db' which contains a table called 'sensor_data'. This table has the following columns: 'device_id' (TEXT), 'timestamp' (TEXT), 'temperature' (REAL), and 'humidity' (REAL). The task is to write a code snippet that queries this database to retrieve sensor data based on user input. The user should provide the 'device_id', a starting 'timestamp', and an ending 'timestamp' to filter the data. Additionally, the user should specify a column to sort the results by, which can be either 'temperature', 'humidity', or 'timestamp', and also indicate the sort direction, either 'ASC' for ascending or 'DESC' for descending. The code should execute the query with these inputs and print the results.
[Example Input & Output]
- Input: sensor_1\n2023-10-01 09:30:00\n2023-10-01 10:30:00\nhumidity\nDESC\n ; Output: ('sensor_1', '2023-10-01 10:00:00', 22.5, 45.0)
- Input: sensor_7\n2023-10-01 15:00:00\n2023-10-01 17:00:00\ntemperature\nASC\n ; Output: ('sensor_7', '2023-10-01 16:00:00', 23.9, 40.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_453_database.db' which contains a table called 'sensor_data'. This table has the following columns: 'device_id' (TEXT), 'timestamp' (TEXT), 'temperature' (REAL), and 'humidity' (REAL). The task is to write a code snippet that queries this database to retrieve sensor data based on user input. The user should provide the 'device_id', a starting 'timestamp', and an ending 'timestamp' to filter the data. Additionally, the user should specify a column to sort the results by, which can be either 'temperature', 'humidity', or 'timestamp', and also indicate the sort direction, either 'ASC' for ascending or 'DESC' for descending. The code should execute the query with these inputs and print the results.
[Example Input & Output]
- Input: sensor_1\n2023-10-01 09:30:00\n2023-10-01 10:30:00\nhumidity\nDESC\n ; Output: ('sensor_1', '2023-10-01 10:00:00', 22.5, 45.0)
- Input: sensor_7\n2023-10-01 15:00:00\n2023-10-01 17:00:00\ntemperature\nASC\n ; Output: ('sensor_7', '2023-10-01 16:00:00', 23.9, 40.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def query_sensor_data():
# Connect to the SQLite database
conn = sqlite3.connect('program_453_database.db')
cursor = conn.cursor()
# Prompt user for inputs
device_id = input("Enter Device ID: ")
start_timestamp = input("Enter Start Timestamp (YYYY-MM-DD HH:MM:SS): ")
end_timestamp = input("Enter End Timestamp (YYYY-MM-DD HH:MM:SS): ")
sort_column = input("Enter Sort Column: ")
sort_direction = input("Enter Sort Direction (ASC/DESC): ")
# Validate date formats
try:
datetime.strptime(start_timestamp, '%Y-%m-%d %H:%M:%S')
datetime.strptime(end_timestamp, '%Y-%m-%d %H:%M:%S')
except ValueError:
print("Invalid date format. Please use YYYY-MM-DD HH:MM:SS.")
return
# Construct SQL query with parameterized query to prevent SQL injection
query = """
SELECT * FROM sensor_data
WHERE device_id = ? AND timestamp BETWEEN ? AND ?
ORDER BY ? ?;
"""
# Execute the query
cursor.execute(query, (device_id, start_timestamp, end_timestamp, sort_column, sort_direction))
# Fetch and print results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No data found.")
# Close the database connection
conn.close()
# Example usage
query_sensor_data()
|
program_350
|
[
{
"content": "[Problem]\nWe have a SQLite database file named 'program_350_database.db' which contains a table called 'customers'. This table has four columns: 'customer_id' (an integer and the primary key), 'name' (a text field), 'email' (a text field), and 'balance' (a real number representing the customer's balance). The task is to connect to this database and execute a SQL query that retrieves all customer records where the customer's name matches a user-provided input and their balance is greater than another user-provided input. The program should prompt the user to input a customer name and a minimum balance, then execute the query and print out the results. The inputs are expected to be a string for the customer name and a number for the minimum balance.\n\n[Example Input & Output]\n- Input: Bob\\n1000\\n ; Output: (2, 'Bob', '[email protected]', 1200.0)\n- Input: Alice\\n1400\\n ; Output: (1, 'Alice', '[email protected]', 1500.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a SQLite database file named 'program_350_database.db' which contains a table called 'customers'. This table has four columns: 'customer_id' (an integer and the primary key), 'name' (a text field), 'email' (a text field), and 'balance' (a real number representing the customer's balance). The task is to connect to this database and execute a SQL query that retrieves all customer records where the customer's name matches a user-provided input and their balance is greater than another user-provided input. The program should prompt the user to input a customer name and a minimum balance, then execute the query and print out the results. The inputs are expected to be a string for the customer name and a number for the minimum balance.
[Example Input & Output]
- Input: Bob\n1000\n ; Output: (2, 'Bob', '[email protected]', 1200.0)
- Input: Alice\n1400\n ; Output: (1, 'Alice', '[email protected]', 1500.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a SQLite database file named 'program_350_database.db' which contains a table called 'customers'. This table has four columns: 'customer_id' (an integer and the primary key), 'name' (a text field), 'email' (a text field), and 'balance' (a real number representing the customer's balance). The task is to connect to this database and execute a SQL query that retrieves all customer records where the customer's name matches a user-provided input and their balance is greater than another user-provided input. The program should prompt the user to input a customer name and a minimum balance, then execute the query and print out the results. The inputs are expected to be a string for the customer name and a number for the minimum balance.
[Example Input & Output]
- Input: Bob\n1000\n ; Output: (2, 'Bob', '[email protected]', 1200.0)
- Input: Alice\n1400\n ; Output: (1, 'Alice', '[email protected]', 1500.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_350_database.db')
# Create a cursor object using the cursor() method
cursor = conn.cursor()
# Prompt the user to enter a customer name and a minimum balance
customer_name = input("Enter customer name: ")
min_balance = float(input("Enter minimum balance: "))
# Execute the query to select customer_id, name, email, and balance
cursor.execute("SELECT customer_id, name, email, balance FROM customers WHERE name=? AND balance > ?", (customer_name, min_balance))
# Fetch all the results
results = cursor.fetchall()
# Print all the results
for row in results:
print(row)
# Close the database connection
conn.close()
|
program_89
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_89_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), stock (INTEGER), and price (REAL). The task is to prompt the user to input a field to search by, which can be either item_id, item_name, or category, and then ask for a value to search for within that field. The script should then execute a query to retrieve and print all rows from the 'inventory' table where the specified field matches the given value. Ensure the script handles any potential errors during query execution.\n\n[Example Input & Output]\n- Input: item_name\\nJacket\\n ; Output: (4, 'Jacket', 'Apparel', 100, 75.0)\n- Input: item_id\\n10\\n ; Output: (10, 'Blender', 'Home Appliances', 50, 55.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_89_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), stock (INTEGER), and price (REAL). The task is to prompt the user to input a field to search by, which can be either item_id, item_name, or category, and then ask for a value to search for within that field. The script should then execute a query to retrieve and print all rows from the 'inventory' table where the specified field matches the given value. Ensure the script handles any potential errors during query execution.
[Example Input & Output]
- Input: item_name\nJacket\n ; Output: (4, 'Jacket', 'Apparel', 100, 75.0)
- Input: item_id\n10\n ; Output: (10, 'Blender', 'Home Appliances', 50, 55.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_89_database.db' and interacts with a table called 'inventory'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), stock (INTEGER), and price (REAL). The task is to prompt the user to input a field to search by, which can be either item_id, item_name, or category, and then ask for a value to search for within that field. The script should then execute a query to retrieve and print all rows from the 'inventory' table where the specified field matches the given value. Ensure the script handles any potential errors during query execution.
[Example Input & Output]
- Input: item_name\nJacket\n ; Output: (4, 'Jacket', 'Apparel', 100, 75.0)
- Input: item_id\n10\n ; Output: (10, 'Blender', 'Home Appliances', 50, 55.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_inventory():
# Connect to the SQLite database
conn = sqlite3.connect('program_89_database.db')
cursor = conn.cursor()
# Prompt the user for search criteria
field = input("Enter the field to search by (item_id, item_name, category): ")
value = input("Enter the value to search for: ")
# Construct and execute the SQL query
query = f"SELECT * FROM inventory WHERE {field} = ?"
cursor.execute(query, (value,))
# Fetch and print the results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No results found.")
# Handle exceptions
except sqlite3.Error as e:
print(f"An error occurred: {e}")
# Close the database connection
finally:
conn.close()
# Call the function to start the search
search_inventory()
|
program_430
|
[
{
"content": "[Problem]\nYou have a database file named 'program_430_database.db' which contains a table called 'transactions'. This table has the following columns: trans_id (INTEGER), payer (TEXT), payee (TEXT), amount (REAL), and status (TEXT). Your task is to write a code snippet that connects to this database and retrieves all transactions where the payer's name matches a user-provided input and the transaction amount is greater than or equal to another user-provided input. The code should prompt the user to enter the payer's name and the minimum amount, then execute a query to fetch and print all matching records from the 'transactions' table.\n\n[Example Input & Output]\n- Input: Alice\\n75\\n ; Output: (1, 'Alice', 'Bob', 100.0, 'completed')\n- Input: Charlie\\n100\\n ; Output: (2, 'Charlie', 'Dave', 250.0, 'pending')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_430_database.db' which contains a table called 'transactions'. This table has the following columns: trans_id (INTEGER), payer (TEXT), payee (TEXT), amount (REAL), and status (TEXT). Your task is to write a code snippet that connects to this database and retrieves all transactions where the payer's name matches a user-provided input and the transaction amount is greater than or equal to another user-provided input. The code should prompt the user to enter the payer's name and the minimum amount, then execute a query to fetch and print all matching records from the 'transactions' table.
[Example Input & Output]
- Input: Alice\n75\n ; Output: (1, 'Alice', 'Bob', 100.0, 'completed')
- Input: Charlie\n100\n ; Output: (2, 'Charlie', 'Dave', 250.0, 'pending')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_430_database.db' which contains a table called 'transactions'. This table has the following columns: trans_id (INTEGER), payer (TEXT), payee (TEXT), amount (REAL), and status (TEXT). Your task is to write a code snippet that connects to this database and retrieves all transactions where the payer's name matches a user-provided input and the transaction amount is greater than or equal to another user-provided input. The code should prompt the user to enter the payer's name and the minimum amount, then execute a query to fetch and print all matching records from the 'transactions' table.
[Example Input & Output]
- Input: Alice\n75\n ; Output: (1, 'Alice', 'Bob', 100.0, 'completed')
- Input: Charlie\n100\n ; Output: (2, 'Charlie', 'Dave', 250.0, 'pending')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_430_database.db')
cursor = conn.cursor()
# Prompt the user for input
payer_name = input("Enter payer's name: ")
min_amount = float(input("Enter minimum amount: "))
# Execute the SQL query
cursor.execute("SELECT * FROM transactions WHERE payer = ? AND amount >= ?", (payer_name, min_amount))
# Fetch and print all matching records
records = cursor.fetchall()
for record in records:
print(record)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_437
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_437_database.db'. This database contains a table called 'accounts' with the following columns: 'account_number' (an integer serving as the primary key), 'holder_name' (a text field), and 'balance' (a real number representing the account balance). The task is to prompt the user to input an account number and then retrieve and print the holder's name and balance associated with that account number from the 'accounts' table. If the account number is not found, print a message indicating that the account is not found. The script should establish a connection to the database, execute the necessary SQL query to fetch the data, and then close the connection.\n\n[Example Input & Output]\n- Input: 1022\\n ; Output: Account not found.\n- Input: 1020\\n ; Output: Account not found.\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_437_database.db'. This database contains a table called 'accounts' with the following columns: 'account_number' (an integer serving as the primary key), 'holder_name' (a text field), and 'balance' (a real number representing the account balance). The task is to prompt the user to input an account number and then retrieve and print the holder's name and balance associated with that account number from the 'accounts' table. If the account number is not found, print a message indicating that the account is not found. The script should establish a connection to the database, execute the necessary SQL query to fetch the data, and then close the connection.
[Example Input & Output]
- Input: 1022\n ; Output: Account not found.
- Input: 1020\n ; Output: Account not found.
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_437_database.db'. This database contains a table called 'accounts' with the following columns: 'account_number' (an integer serving as the primary key), 'holder_name' (a text field), and 'balance' (a real number representing the account balance). The task is to prompt the user to input an account number and then retrieve and print the holder's name and balance associated with that account number from the 'accounts' table. If the account number is not found, print a message indicating that the account is not found. The script should establish a connection to the database, execute the necessary SQL query to fetch the data, and then close the connection.
[Example Input & Output]
- Input: 1022\n ; Output: Account not found.
- Input: 1020\n ; Output: Account not found.
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_account_info(account_number):
# Connect to the SQLite database
conn = sqlite3.connect('program_437_database.db')
cursor = conn.cursor()
# Retrieve the holder's name and balance using the provided account number
cursor.execute("SELECT holder_name, balance FROM accounts WHERE account_number = ?", (account_number,))
result = cursor.fetchone()
if result:
holder_name, balance = result
print(f"Holder's Name: {holder_name}, Balance: {balance}")
else:
print("Account not found.")
# Close the database connection
conn.close()
# Prompt the user to input an account number
account_number = input("Enter account number: ")
# Call the function to retrieve and display the account information
get_account_info(account_number)
|
program_463
|
[
{
"content": "[Problem]\nWe have a SQLite database named 'program_463_database.db' which contains a table called 'inventory'. This table has the following columns: 'item_id' (an integer primary key), 'item_name' (a text field), 'item_description' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to create a script that connects to this database and allows a user to input the name of an item they wish to search for in the inventory. The script should then execute a query to find and print all details of the item(s) with the specified name. The input required is a single string representing the name of the item to search for.\n\n[Example Input & Output]\n- Input: Laptop\\n ; Output: (4, 'Laptop', 'A powerful laptop for everyday use', 30, 899.99)\n- Input: Tablet\\n ; Output: (7, 'Tablet', 'A lightweight tablet for on-the-go use', 75, 329.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a SQLite database named 'program_463_database.db' which contains a table called 'inventory'. This table has the following columns: 'item_id' (an integer primary key), 'item_name' (a text field), 'item_description' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to create a script that connects to this database and allows a user to input the name of an item they wish to search for in the inventory. The script should then execute a query to find and print all details of the item(s) with the specified name. The input required is a single string representing the name of the item to search for.
[Example Input & Output]
- Input: Laptop\n ; Output: (4, 'Laptop', 'A powerful laptop for everyday use', 30, 899.99)
- Input: Tablet\n ; Output: (7, 'Tablet', 'A lightweight tablet for on-the-go use', 75, 329.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a SQLite database named 'program_463_database.db' which contains a table called 'inventory'. This table has the following columns: 'item_id' (an integer primary key), 'item_name' (a text field), 'item_description' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to create a script that connects to this database and allows a user to input the name of an item they wish to search for in the inventory. The script should then execute a query to find and print all details of the item(s) with the specified name. The input required is a single string representing the name of the item to search for.
[Example Input & Output]
- Input: Laptop\n ; Output: (4, 'Laptop', 'A powerful laptop for everyday use', 30, 899.99)
- Input: Tablet\n ; Output: (7, 'Tablet', 'A lightweight tablet for on-the-go use', 75, 329.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_463_database.db')
cursor = conn.cursor()
# Prompt the user to enter an item name to search for
item_name = input("Enter the item name to search for: ")
# Execute a query to select all rows from the 'inventory' table where the 'item_name' column contains the entered item name
cursor.execute("SELECT * FROM inventory WHERE item_name LIKE ?", ('%' + item_name + '%',))
# Fetch and print all the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_150
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_150_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id, product_name, customer, shipping_address, and status. The task is to prompt the user to input a customer name and then retrieve and print all orders associated with that customer from the 'orders' table. The input should be a single string representing the customer name.\n\n[Example Input & Output]\n- Input: Hank\\n ; Output: (8, 'Keyboard', 'Hank', '753 Willow Way', 'Shipped')\n- Input: Dave\\n ; Output: (4, 'Tablet', 'Dave', '321 Elm St', 'Shipped')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_150_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id, product_name, customer, shipping_address, and status. The task is to prompt the user to input a customer name and then retrieve and print all orders associated with that customer from the 'orders' table. The input should be a single string representing the customer name.
[Example Input & Output]
- Input: Hank\n ; Output: (8, 'Keyboard', 'Hank', '753 Willow Way', 'Shipped')
- Input: Dave\n ; Output: (4, 'Tablet', 'Dave', '321 Elm St', 'Shipped')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_150_database.db' and queries a table called 'orders'. The 'orders' table contains the following columns: order_id, product_name, customer, shipping_address, and status. The task is to prompt the user to input a customer name and then retrieve and print all orders associated with that customer from the 'orders' table. The input should be a single string representing the customer name.
[Example Input & Output]
- Input: Hank\n ; Output: (8, 'Keyboard', 'Hank', '753 Willow Way', 'Shipped')
- Input: Dave\n ; Output: (4, 'Tablet', 'Dave', '321 Elm St', 'Shipped')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import os
def get_customer_orders(customer_name):
# Connect to the SQLite database
conn = sqlite3.connect('program_150_database.db')
cursor = conn.cursor()
# Retrieve orders for the specified customer
query = "SELECT * FROM orders WHERE customer_name = ?"
cursor.execute(query, (customer_name,))
orders = cursor.fetchall()
# Print the results
if orders:
print(f"Orders for {customer_name}:")
for order in orders:
print(order)
else:
print(f"No orders found for {customer_name}.")
# Close the database connection
conn.close()
if __name__ == "__main__":
# Prompt the user to input a customer name
customer_name = input("Enter the customer name: ")
# Retrieve and print the customer's orders
get_customer_orders(customer_name)
|
program_275
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_275_database.db' and interacts with a table called 'students'. The table contains columns: student_id, name, age, major, and gpa. The task is to take two inputs from the user: the name of a student and a choice to view GPA details. Based on these inputs, construct and execute a SQL query to retrieve and print all columns for the student with the specified name. If the user chooses to view GPA details, ensure the query includes a condition to check that the GPA is greater than 0. Finally, display the results of the query.\n\n[Example Input & Output]\n- Input: Charlie\\nyes\\n ; Output: (3, 'Charlie', 21, 'Physics', 3.5)\n- Input: David\\nno\\n ; Output: (4, 'David', 23, 'Biology', 3.6)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_275_database.db' and interacts with a table called 'students'. The table contains columns: student_id, name, age, major, and gpa. The task is to take two inputs from the user: the name of a student and a choice to view GPA details. Based on these inputs, construct and execute a SQL query to retrieve and print all columns for the student with the specified name. If the user chooses to view GPA details, ensure the query includes a condition to check that the GPA is greater than 0. Finally, display the results of the query.
[Example Input & Output]
- Input: Charlie\nyes\n ; Output: (3, 'Charlie', 21, 'Physics', 3.5)
- Input: David\nno\n ; Output: (4, 'David', 23, 'Biology', 3.6)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_275_database.db' and interacts with a table called 'students'. The table contains columns: student_id, name, age, major, and gpa. The task is to take two inputs from the user: the name of a student and a choice to view GPA details. Based on these inputs, construct and execute a SQL query to retrieve and print all columns for the student with the specified name. If the user chooses to view GPA details, ensure the query includes a condition to check that the GPA is greater than 0. Finally, display the results of the query.
[Example Input & Output]
- Input: Charlie\nyes\n ; Output: (3, 'Charlie', 21, 'Physics', 3.5)
- Input: David\nno\n ; Output: (4, 'David', 23, 'Biology', 3.6)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def execute_query(name, view_gpa):
# Establish a connection to the SQLite database
conn = sqlite3.connect('program_275_database.db')
cursor = conn.cursor()
# Construct the SQL query based on the input parameters
if view_gpa.lower() == 'yes':
query = "SELECT * FROM students WHERE name=? AND gpa>0"
else:
query = "SELECT * FROM students WHERE name=?"
# Execute the query with the provided name
cursor.execute(query, (name,))
# Fetch all results and print each row
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
# Prompt the user for input and call the execute_query function
student_name = input("Enter the student's name: ")
view_gpa = input("Do you want to view GPA details? (yes/no): ")
execute_query(student_name, view_gpa)
|
program_82
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_82_database.db' and interacts with a table called 'users'. This table contains columns 'user_id', 'username', and 'email'. The task is to prompt the user to input a username and then retrieve and print the corresponding email address from the database. The input should be a single string representing the username. Ensure the script establishes a connection to the database, executes the necessary SQL query to find the email based on the provided username, and then outputs the result. If the username is not found, the script should print \"User not found.\" Finally, ensure the database connection is properly closed after the operation.\n\n[Example Input & Output]\n- Input: alice\\n ; Output: [email protected]\n- Input: carol\\n ; Output: [email protected]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_82_database.db' and interacts with a table called 'users'. This table contains columns 'user_id', 'username', and 'email'. The task is to prompt the user to input a username and then retrieve and print the corresponding email address from the database. The input should be a single string representing the username. Ensure the script establishes a connection to the database, executes the necessary SQL query to find the email based on the provided username, and then outputs the result. If the username is not found, the script should print "User not found." Finally, ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: alice\n ; Output: [email protected]
- Input: carol\n ; Output: [email protected]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_82_database.db' and interacts with a table called 'users'. This table contains columns 'user_id', 'username', and 'email'. The task is to prompt the user to input a username and then retrieve and print the corresponding email address from the database. The input should be a single string representing the username. Ensure the script establishes a connection to the database, executes the necessary SQL query to find the email based on the provided username, and then outputs the result. If the username is not found, the script should print "User not found." Finally, ensure the database connection is properly closed after the operation.
[Example Input & Output]
- Input: alice\n ; Output: [email protected]
- Input: carol\n ; Output: [email protected]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_user_email(username):
# Connect to the SQLite database
conn = sqlite3.connect('program_82_database.db')
cursor = conn.cursor()
try:
# Execute the SQL query to retrieve the email
cursor.execute("SELECT email FROM users WHERE username=?", (username,))
result = cursor.fetchone()
if result:
# Print the email if the user is found
print(result[0])
else:
# Print "User not found" if the user is not found
print("User not found.")
finally:
# Close the database connection
conn.close()
# Prompt the user to input a username
username = input("Enter username: ")
# Call the function to get the user's email
get_user_email(username)
|
program_485
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_485_database.db' and queries a table called 'census'. The table has columns named 'id', 'name', 'age', 'occupation', and 'region'. The task is to prompt the user for two inputs: 'occupation' and 'region'. Use these inputs to construct and execute a SQL query that selects all records from the 'census' table where the 'occupation' matches the first input and the 'region' matches the second input. Finally, print the results of the query. Do not worry about any potential security issues in the query construction.\n\n[Example Input & Output]\n- Input: Writer\\nSouth\\n ; Output: []\n- Input: Artist\\nSouth\\n ; Output: [(10, 'Jack Turner', 27, 'Artist', 'South')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_485_database.db' and queries a table called 'census'. The table has columns named 'id', 'name', 'age', 'occupation', and 'region'. The task is to prompt the user for two inputs: 'occupation' and 'region'. Use these inputs to construct and execute a SQL query that selects all records from the 'census' table where the 'occupation' matches the first input and the 'region' matches the second input. Finally, print the results of the query. Do not worry about any potential security issues in the query construction.
[Example Input & Output]
- Input: Writer\nSouth\n ; Output: []
- Input: Artist\nSouth\n ; Output: [(10, 'Jack Turner', 27, 'Artist', 'South')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_485_database.db' and queries a table called 'census'. The table has columns named 'id', 'name', 'age', 'occupation', and 'region'. The task is to prompt the user for two inputs: 'occupation' and 'region'. Use these inputs to construct and execute a SQL query that selects all records from the 'census' table where the 'occupation' matches the first input and the 'region' matches the second input. Finally, print the results of the query. Do not worry about any potential security issues in the query construction.
[Example Input & Output]
- Input: Writer\nSouth\n ; Output: []
- Input: Artist\nSouth\n ; Output: [(10, 'Jack Turner', 27, 'Artist', 'South')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
# Connect to the SQLite database
conn = sqlite3.connect('program_485_database.db')
# Prompt the user for their occupation and region
occupation = input("Enter your occupation: ")
region = input("Enter your region: ")
# Construct and execute the SQL query
cursor = conn.cursor()
query = "SELECT * FROM census WHERE occupation=? AND region=?"
cursor.execute(query, (occupation, region))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
|
program_171
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_171_database.db' and interacts with a table called 'employees'. The table has the following columns: emp_id, first_name, last_name, department, and salary. The task is to prompt the user for three inputs: a department name to filter the employees by, a column name to order the results by, and the order direction (either ASC or DESC). The script should then execute a SQL query to select the emp_id, first_name, and last_name of employees from the specified department, ordered by the specified column and direction, and print the results. Ensure the script handles any exceptions that may occur during the execution of the query.\n\n[Example Input & Output]\n- Input: Sales\\nfirst_name\\nDESC\\n ; Output: 6 Michael Wilson\\n3 Alice Johnson\n- Input: Engineering\\nsalary\\nASC\\n ; Output: 1 John Doe\\n4 Bob Brown\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_171_database.db' and interacts with a table called 'employees'. The table has the following columns: emp_id, first_name, last_name, department, and salary. The task is to prompt the user for three inputs: a department name to filter the employees by, a column name to order the results by, and the order direction (either ASC or DESC). The script should then execute a SQL query to select the emp_id, first_name, and last_name of employees from the specified department, ordered by the specified column and direction, and print the results. Ensure the script handles any exceptions that may occur during the execution of the query.
[Example Input & Output]
- Input: Sales\nfirst_name\nDESC\n ; Output: 6 Michael Wilson\n3 Alice Johnson
- Input: Engineering\nsalary\nASC\n ; Output: 1 John Doe\n4 Bob Brown
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_171_database.db' and interacts with a table called 'employees'. The table has the following columns: emp_id, first_name, last_name, department, and salary. The task is to prompt the user for three inputs: a department name to filter the employees by, a column name to order the results by, and the order direction (either ASC or DESC). The script should then execute a SQL query to select the emp_id, first_name, and last_name of employees from the specified department, ordered by the specified column and direction, and print the results. Ensure the script handles any exceptions that may occur during the execution of the query.
[Example Input & Output]
- Input: Sales\nfirst_name\nDESC\n ; Output: 6 Michael Wilson\n3 Alice Johnson
- Input: Engineering\nsalary\nASC\n ; Output: 1 John Doe\n4 Bob Brown
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print("Connected to SQLite database")
except Error as e:
print(e)
return conn
def select_query(conn, query):
try:
cursor = conn.cursor()
cursor.execute(query)
rows = cursor.fetchall()
for row in rows:
print(row)
except Error as e:
print(e)
def main():
db_file = 'program_171_database.db'
conn = create_connection(db_file)
if conn is not None:
department_name = input("Enter department name: ")
column_name = input("Enter column name to order by: ")
order_direction = input("Enter order direction (ASC/DESC): ")
# Construct SQL query
query = f"""
SELECT emp_id, first_name, last_name
FROM employees
WHERE department = ?
ORDER BY {column_name} {order_direction};
"""
# Execute query
select_query(conn, query)
finally:
if conn:
conn.close()
print("SQLite connection closed")
if __name__ == "__main__":
main()
|
program_181
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_181_database.db' and queries a table called 'players'. The 'players' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'team' (TEXT), 'position' (TEXT), and 'average' (REAL). The task is to prompt the user for four inputs: a team name, a player position, a minimum average, and a column to sort by (either 'name', 'team', 'position', or 'average'). Additionally, ask for the sorting order, which can be either 'ASC' for ascending or 'DESC' for descending. Construct an SQL query to select all players from the specified team and position with an average greater than or equal to the given minimum, and sort the results based on the chosen column and order. Finally, execute the query and print each resulting row.\n\n[Example Input & Output]\n- Input: Sharks\\nDefender\\n24\\nname\\nDESC\\n ; Output: (7, 'David Lee', 'Sharks', 'Defender', 24.7)\n- Input: Tigers\\nMidfielder\\n20.0\\naverage\\nDESC\\n ; Output: (8, 'Rachel Green', 'Tigers', 'Midfielder', 26.9)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_181_database.db' and queries a table called 'players'. The 'players' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'team' (TEXT), 'position' (TEXT), and 'average' (REAL). The task is to prompt the user for four inputs: a team name, a player position, a minimum average, and a column to sort by (either 'name', 'team', 'position', or 'average'). Additionally, ask for the sorting order, which can be either 'ASC' for ascending or 'DESC' for descending. Construct an SQL query to select all players from the specified team and position with an average greater than or equal to the given minimum, and sort the results based on the chosen column and order. Finally, execute the query and print each resulting row.
[Example Input & Output]
- Input: Sharks\nDefender\n24\nname\nDESC\n ; Output: (7, 'David Lee', 'Sharks', 'Defender', 24.7)
- Input: Tigers\nMidfielder\n20.0\naverage\nDESC\n ; Output: (8, 'Rachel Green', 'Tigers', 'Midfielder', 26.9)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_181_database.db' and queries a table called 'players'. The 'players' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'team' (TEXT), 'position' (TEXT), and 'average' (REAL). The task is to prompt the user for four inputs: a team name, a player position, a minimum average, and a column to sort by (either 'name', 'team', 'position', or 'average'). Additionally, ask for the sorting order, which can be either 'ASC' for ascending or 'DESC' for descending. Construct an SQL query to select all players from the specified team and position with an average greater than or equal to the given minimum, and sort the results based on the chosen column and order. Finally, execute the query and print each resulting row.
[Example Input & Output]
- Input: Sharks\nDefender\n24\nname\nDESC\n ; Output: (7, 'David Lee', 'Sharks', 'Defender', 24.7)
- Input: Tigers\nMidfielder\n20.0\naverage\nDESC\n ; Output: (8, 'Rachel Green', 'Tigers', 'Midfielder', 26.9)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to the SQLite database {db_file}')
except Error as e:
print(e)
return conn
def execute_query(conn, query, params=None):
cur = conn.cursor()
if params:
cur.execute(query, params)
else:
cur.execute(query)
conn.commit()
def fetch_data(conn, query, params=None):
cur = conn.cursor()
if params:
cur.execute(query, params)
else:
cur.execute(query)
rows = cur.fetchall()
return rows
def main():
db_file = 'program_181_database.db'
conn = create_connection(db_file)
if conn is not None:
try:
team_name = input("Enter team name: ")
player_position = input("Enter player position: ")
min_average = float(input("Enter minimum average: "))
column_to_sort_by = input("Enter column to sort by: ")
sorting_order = input("Enter sorting order (ASC/DESC): ")
query = '''
SELECT * FROM players
WHERE team_name = ? AND player_position = ? AND average >= ?
ORDER BY ? ASC DESC LIMIT 100;
'''
params = (team_name, player_position, min_average, column_to_sort_by, sorting_order)
data = fetch_data(conn, query, params)
for row in data:
print(row)
except Error as e:
print(e)
finally:
conn.close()
if __name__ == '__main__':
main()
|
program_283
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_283_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER PRIMARY KEY), emp_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user for two inputs: a department name and a minimum salary. Use these inputs to construct and execute a SQL query that retrieves all employees from the specified department with a salary greater than or equal to the given minimum salary. Finally, print the results of the query.\n\n[Example Input & Output]\n- Input: Marketing\\n74000\\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)\n- Input: Marketing\\n70000\\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_283_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER PRIMARY KEY), emp_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user for two inputs: a department name and a minimum salary. Use these inputs to construct and execute a SQL query that retrieves all employees from the specified department with a salary greater than or equal to the given minimum salary. Finally, print the results of the query.
[Example Input & Output]
- Input: Marketing\n74000\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)
- Input: Marketing\n70000\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_283_database.db' and queries a table called 'employees'. The table has the following columns: emp_id (INTEGER PRIMARY KEY), emp_name (TEXT), department (TEXT), and salary (REAL). The task is to prompt the user for two inputs: a department name and a minimum salary. Use these inputs to construct and execute a SQL query that retrieves all employees from the specified department with a salary greater than or equal to the given minimum salary. Finally, print the results of the query.
[Example Input & Output]
- Input: Marketing\n74000\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)
- Input: Marketing\n70000\n ; Output: (6, 'Fiona White', 'Marketing', 75000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from os import getenv
def get_department_name():
return input("Enter department name: ")
def get_minimum_salary():
return int(input("Enter minimum salary: "))
def execute_query(conn, department_name, minimum_salary):
cursor = conn.cursor()
query = """
SELECT employee_id, name, department, salary
FROM employees
WHERE department = ? AND salary >= ?
"""
cursor.execute(query, (department_name, minimum_salary))
results = cursor.fetchall()
for row in results:
print(row)
def main():
db_name = getenv('DATABASE_NAME', 'program_283_database.db')
conn = sqlite3.connect(db_name)
department_name = get_department_name()
minimum_salary = get_minimum_salary()
execute_query(conn, department_name, minimum_salary)
conn.close()
if __name__ == "__main__":
main()
|
program_191
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_191_database.db' which contains a table called 'orders'. The 'orders' table has the following columns: order_id (INTEGER), customer_name (TEXT), dish (TEXT), quantity (INTEGER), and price (REAL). The task is to take four inputs from the user: a customer name for verification, a minimum quantity to filter orders, a dish type preference, and a price limit to filter orders. Use these inputs to construct and execute an SQL query that selects all orders from the 'orders' table where the customer_name matches the input and either the quantity is greater than or equal to the minimum quantity, the dish matches the dish type preference, or the price is less than or equal to the price limit. Finally, print the results of the query.\n\n[Example Input & Output]\n- Input: Charlie\\n1\\nSteak\\n30\\n ; Output: [(5, 'Charlie', 'Steak', 1, 25.0)]\n- Input: Bob\\n2\\nSandwich\\n15\\n ; Output: [(4, 'Bob', 'Burger', 1, 10.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_191_database.db' which contains a table called 'orders'. The 'orders' table has the following columns: order_id (INTEGER), customer_name (TEXT), dish (TEXT), quantity (INTEGER), and price (REAL). The task is to take four inputs from the user: a customer name for verification, a minimum quantity to filter orders, a dish type preference, and a price limit to filter orders. Use these inputs to construct and execute an SQL query that selects all orders from the 'orders' table where the customer_name matches the input and either the quantity is greater than or equal to the minimum quantity, the dish matches the dish type preference, or the price is less than or equal to the price limit. Finally, print the results of the query.
[Example Input & Output]
- Input: Charlie\n1\nSteak\n30\n ; Output: [(5, 'Charlie', 'Steak', 1, 25.0)]
- Input: Bob\n2\nSandwich\n15\n ; Output: [(4, 'Bob', 'Burger', 1, 10.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_191_database.db' which contains a table called 'orders'. The 'orders' table has the following columns: order_id (INTEGER), customer_name (TEXT), dish (TEXT), quantity (INTEGER), and price (REAL). The task is to take four inputs from the user: a customer name for verification, a minimum quantity to filter orders, a dish type preference, and a price limit to filter orders. Use these inputs to construct and execute an SQL query that selects all orders from the 'orders' table where the customer_name matches the input and either the quantity is greater than or equal to the minimum quantity, the dish matches the dish type preference, or the price is less than or equal to the price limit. Finally, print the results of the query.
[Example Input & Output]
- Input: Charlie\n1\nSteak\n30\n ; Output: [(5, 'Charlie', 'Steak', 1, 25.0)]
- Input: Bob\n2\nSandwich\n15\n ; Output: [(4, 'Bob', 'Burger', 1, 10.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_191_database.db')
cursor = conn.cursor()
# Prompt the user for input
customer_name = input("Enter customer name: ")
min_quantity = int(input("Enter minimum quantity: "))
dish_type_preference = input("Enter dish type preference: ")
price_limit = float(input("Enter price limit: "))
# Construct the SQL query with parameterized queries to prevent SQL injection
query = """
SELECT order_id, customer_name, dish, quantity, price
FROM orders
WHERE customer_name = ? AND quantity >= ? AND dish LIKE ? AND price <= ?
"""
# Execute the query with user inputs
cursor.execute(query, (customer_name, min_quantity, f"%{dish_type_preference}%", price_limit))
# Fetch all results
results = cursor.fetchall()
# Print the results
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_202
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_202_database.db' and queries a table called 'customer_bills'. The table contains columns named 'customer_id', 'name', 'phone', and 'amount_due'. The task is to prompt the user for two inputs: a phone number and a minimum amount due. Use these inputs to construct and execute a SQL query that selects all records from the 'customer_bills' table where the 'phone' matches the input phone number and the 'amount_due' is greater than the input minimum amount due. Finally, print the results of the query.\n\n[Example Input & Output]\n- Input: 555-4321\\n119\\n ; Output: (4, 'David', '555-4321', 120.0)\n- Input: 555-9876\\n50\\n ; Output: (6, 'Frank', '555-9876', 60.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_202_database.db' and queries a table called 'customer_bills'. The table contains columns named 'customer_id', 'name', 'phone', and 'amount_due'. The task is to prompt the user for two inputs: a phone number and a minimum amount due. Use these inputs to construct and execute a SQL query that selects all records from the 'customer_bills' table where the 'phone' matches the input phone number and the 'amount_due' is greater than the input minimum amount due. Finally, print the results of the query.
[Example Input & Output]
- Input: 555-4321\n119\n ; Output: (4, 'David', '555-4321', 120.0)
- Input: 555-9876\n50\n ; Output: (6, 'Frank', '555-9876', 60.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_202_database.db' and queries a table called 'customer_bills'. The table contains columns named 'customer_id', 'name', 'phone', and 'amount_due'. The task is to prompt the user for two inputs: a phone number and a minimum amount due. Use these inputs to construct and execute a SQL query that selects all records from the 'customer_bills' table where the 'phone' matches the input phone number and the 'amount_due' is greater than the input minimum amount due. Finally, print the results of the query.
[Example Input & Output]
- Input: 555-4321\n119\n ; Output: (4, 'David', '555-4321', 120.0)
- Input: 555-9876\n50\n ; Output: (6, 'Frank', '555-9876', 60.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_user_input():
phone_number = input("Enter phone number: ")
min_amount_due = float(input("Enter minimum amount due: "))
return phone_number, min_amount_due
def execute_query(phone_number, min_amount_due):
conn = sqlite3.connect('program_202_database.db')
cursor = conn.cursor()
cursor.execute("""
SELECT customer_id, name, phone, amount_due
FROM customer_bills
WHERE phone = ? AND amount_due > ?
""", (phone_number, min_amount_due))
results = cursor.fetchall()
for result in results:
print(result)
conn.close()
if __name__ == "__main__":
phone_number, min_amount_due = get_user_input()
execute_query(phone_number, min_amount_due)
|
program_56
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_56_database.db' and queries a table called 'items'. The table has the following columns: 'item_id', 'item_name', 'category', 'stock_quantity', and 'price_per_unit'. The task is to prompt the user for input to search for items by their name. The input should be sanitized by removing certain special characters before being used in a SQL query. The script should execute a query to find all items where the 'item_name' contains the user-provided input and print the results. Ensure the database connection is properly closed after executing the query.\n\n[Example Input & Output]\n- Input: Widg\\n ; Output: (1, 'Widget', 'Gadgets', 100, 25.99)\n- Input: Appara\\n ; Output: (8, 'Apparatus', 'Hardware', 80, 29.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_56_database.db' and queries a table called 'items'. The table has the following columns: 'item_id', 'item_name', 'category', 'stock_quantity', and 'price_per_unit'. The task is to prompt the user for input to search for items by their name. The input should be sanitized by removing certain special characters before being used in a SQL query. The script should execute a query to find all items where the 'item_name' contains the user-provided input and print the results. Ensure the database connection is properly closed after executing the query.
[Example Input & Output]
- Input: Widg\n ; Output: (1, 'Widget', 'Gadgets', 100, 25.99)
- Input: Appara\n ; Output: (8, 'Apparatus', 'Hardware', 80, 29.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_56_database.db' and queries a table called 'items'. The table has the following columns: 'item_id', 'item_name', 'category', 'stock_quantity', and 'price_per_unit'. The task is to prompt the user for input to search for items by their name. The input should be sanitized by removing certain special characters before being used in a SQL query. The script should execute a query to find all items where the 'item_name' contains the user-provided input and print the results. Ensure the database connection is properly closed after executing the query.
[Example Input & Output]
- Input: Widg\n ; Output: (1, 'Widget', 'Gadgets', 100, 25.99)
- Input: Appara\n ; Output: (8, 'Apparatus', 'Hardware', 80, 29.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
import re
def search_items_by_name():
# Connect to the SQLite database
conn = sqlite3.connect('program_56_database.db')
cursor = conn.cursor()
# Prompt the user to enter the name of an item
item_name = input("Enter the name of the item to search for: ")
# Sanitize the input using regular expressions
sanitized_name = re.sub(r'[^a-zA-Z0-9\s]', '', item_name)
# Construct and execute the SQL query
cursor.execute("SELECT * FROM items WHERE name LIKE ?", ('%' + sanitized_name + '%',))
# Fetch and print the search results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No items found with the given name.")
# Close the database connection
conn.close()
# Call the function to perform the search
search_items_by_name()
|
program_298
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_298_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id', 'title', 'author', 'year', and 'genre'. The task is to retrieve and print all books that fall within a user-specified publication year range, match a specific genre, and have an author's name that includes a user-provided substring. The script should prompt the user for four inputs: the starting publication year, the ending publication year, the genre, and a partial or full author's name. Use these inputs to filter the results from the 'books' table and display the matching records.\n\n[Example Input & Output]\n- Input: 1920\\n1950\\nFantasy\\nTolkien\\n ; Output: (9, 'The Hobbit', 'J.R.R. Tolkien', 1937, 'Fantasy')\n- Input: 1800\\n1850\\nRomance\\nAusten\\n ; Output: (5, 'Pride and Prejudice', 'Jane Austen', 1813, 'Romance')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_298_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id', 'title', 'author', 'year', and 'genre'. The task is to retrieve and print all books that fall within a user-specified publication year range, match a specific genre, and have an author's name that includes a user-provided substring. The script should prompt the user for four inputs: the starting publication year, the ending publication year, the genre, and a partial or full author's name. Use these inputs to filter the results from the 'books' table and display the matching records.
[Example Input & Output]
- Input: 1920\n1950\nFantasy\nTolkien\n ; Output: (9, 'The Hobbit', 'J.R.R. Tolkien', 1937, 'Fantasy')
- Input: 1800\n1850\nRomance\nAusten\n ; Output: (5, 'Pride and Prejudice', 'Jane Austen', 1813, 'Romance')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_298_database.db' and queries a table called 'books'. The 'books' table contains columns: 'id', 'title', 'author', 'year', and 'genre'. The task is to retrieve and print all books that fall within a user-specified publication year range, match a specific genre, and have an author's name that includes a user-provided substring. The script should prompt the user for four inputs: the starting publication year, the ending publication year, the genre, and a partial or full author's name. Use these inputs to filter the results from the 'books' table and display the matching records.
[Example Input & Output]
- Input: 1920\n1950\nFantasy\nTolkien\n ; Output: (9, 'The Hobbit', 'J.R.R. Tolkien', 1937, 'Fantasy')
- Input: 1800\n1850\nRomance\nAusten\n ; Output: (5, 'Pride and Prejudice', 'Jane Austen', 1813, 'Romance')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_298_database.db')
cursor = conn.cursor()
# Prompt the user for input
start_year = int(input("Enter the starting publication year: "))
end_year = int(input("Enter the ending publication year: "))
genre = input("Enter the genre: ")
author_name = input("Enter the author's name: ")
# Construct the SQL query
query = """
SELECT id, title, author, year, genre
FROM books
WHERE year BETWEEN ? AND ?
AND genre = ?
AND author LIKE ?
"""
# Execute the query with parameters
cursor.execute(query, (start_year, end_year, genre, f"%{author_name}%"))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_320
|
[
{
"content": "[Problem]\nWe have a database file named 'program_320_database.db' which contains a table called 'customers'. This table has the following columns: 'customer_id' (INTEGER), 'name' (TEXT), 'email' (TEXT), and 'balance' (REAL). The task is to write a script that connects to this database and allows a user to search for customers based on their email and account balance. The user should be able to input an email address and specify a minimum and maximum balance range. If an email is provided, the script should filter customers by this email or by the specified balance range. If no email is provided, the script should filter customers only by the balance range. The script should then execute the query and print out the results. The inputs expected from the user are: an email address (which can be left blank), a minimum balance, and a maximum balance.\n\n[Example Input & Output]\n- Input: [email protected]\\n800\\n2000\\n ; Output: (1, 'John Doe', '[email protected]', 1500.0)\\n(2, 'Jane Smith', '[email protected]', 1750.0)\\n(3, 'Jim Brown', '[email protected]', 800.0)\\n(4, 'Jake White', '[email protected]', 1250.0)\\n(5, 'Emily Green', '[email protected]', 1600.0)\\n(6, 'Michael Johnson', '[email protected]', 2000.0)\\n(7, 'Sarah Connor', '[email protected]', 1300.0)\\n(8, 'David Wilson', '[email protected]', 950.0)\n- Input: [email protected]\\n1200\\n1400\\n ; Output: (4, 'Jake White', '[email protected]', 1250.0)\\n(7, 'Sarah Connor', '[email protected]', 1300.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_320_database.db' which contains a table called 'customers'. This table has the following columns: 'customer_id' (INTEGER), 'name' (TEXT), 'email' (TEXT), and 'balance' (REAL). The task is to write a script that connects to this database and allows a user to search for customers based on their email and account balance. The user should be able to input an email address and specify a minimum and maximum balance range. If an email is provided, the script should filter customers by this email or by the specified balance range. If no email is provided, the script should filter customers only by the balance range. The script should then execute the query and print out the results. The inputs expected from the user are: an email address (which can be left blank), a minimum balance, and a maximum balance.
[Example Input & Output]
- Input: [email protected]\n800\n2000\n ; Output: (1, 'John Doe', '[email protected]', 1500.0)\n(2, 'Jane Smith', '[email protected]', 1750.0)\n(3, 'Jim Brown', '[email protected]', 800.0)\n(4, 'Jake White', '[email protected]', 1250.0)\n(5, 'Emily Green', '[email protected]', 1600.0)\n(6, 'Michael Johnson', '[email protected]', 2000.0)\n(7, 'Sarah Connor', '[email protected]', 1300.0)\n(8, 'David Wilson', '[email protected]', 950.0)
- Input: [email protected]\n1200\n1400\n ; Output: (4, 'Jake White', '[email protected]', 1250.0)\n(7, 'Sarah Connor', '[email protected]', 1300.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_320_database.db' which contains a table called 'customers'. This table has the following columns: 'customer_id' (INTEGER), 'name' (TEXT), 'email' (TEXT), and 'balance' (REAL). The task is to write a script that connects to this database and allows a user to search for customers based on their email and account balance. The user should be able to input an email address and specify a minimum and maximum balance range. If an email is provided, the script should filter customers by this email or by the specified balance range. If no email is provided, the script should filter customers only by the balance range. The script should then execute the query and print out the results. The inputs expected from the user are: an email address (which can be left blank), a minimum balance, and a maximum balance.
[Example Input & Output]
- Input: [email protected]\n800\n2000\n ; Output: (1, 'John Doe', '[email protected]', 1500.0)\n(2, 'Jane Smith', '[email protected]', 1750.0)\n(3, 'Jim Brown', '[email protected]', 800.0)\n(4, 'Jake White', '[email protected]', 1250.0)\n(5, 'Emily Green', '[email protected]', 1600.0)\n(6, 'Michael Johnson', '[email protected]', 2000.0)\n(7, 'Sarah Connor', '[email protected]', 1300.0)\n(8, 'David Wilson', '[email protected]', 950.0)
- Input: [email protected]\n1200\n1400\n ; Output: (4, 'Jake White', '[email protected]', 1250.0)\n(7, 'Sarah Connor', '[email protected]', 1300.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_customers():
# Connect to the SQLite database
conn = sqlite3.connect('program_320_database.db')
cursor = conn.cursor()
# Prompt the user for input
email = input("Enter email: ")
min_balance = float(input("Enter minimum balance: "))
max_balance = float(input("Enter maximum balance: "))
# Construct the SQL query with parameterized queries
query = """
SELECT * FROM customers WHERE email = ? AND balance BETWEEN ? AND ?
"""
cursor.execute(query, (email, min_balance, max_balance))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the connection
conn.close()
# Call the function
search_customers()
|
program_111
|
[
{
"content": "[Problem]\nThe database is named 'program_111_database.db' and contains a table called 'inventory'. This table has the following columns: 'item_id' (INTEGER), 'item_name' (TEXT), 'item_type' (TEXT), 'quantity' (INTEGER), and 'cost' (REAL). The task is to connect to this database and retrieve items from the 'inventory' table based on certain conditions. The conditions are derived from user inputs. Specifically, the user will provide four inputs: a base cost, a cost multiplier, a minimum quantity threshold, and an item type. The program should calculate an adjusted cost by multiplying the base cost by the multiplier, and a quantity check by adding 5 to the minimum quantity threshold. The SQL query should then select all items from the 'inventory' table where the cost is less than the adjusted cost, the quantity is greater than the quantity check, and the item type matches the user-provided item type. Finally, the program should print the retrieved items.\n\n[Example Input & Output]\n- Input: 150\\n2.5\\n5\\nSoftware\\n ; Output: []\n- Input: 350\\n0.9\\n25\\nFurniture\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_111_database.db' and contains a table called 'inventory'. This table has the following columns: 'item_id' (INTEGER), 'item_name' (TEXT), 'item_type' (TEXT), 'quantity' (INTEGER), and 'cost' (REAL). The task is to connect to this database and retrieve items from the 'inventory' table based on certain conditions. The conditions are derived from user inputs. Specifically, the user will provide four inputs: a base cost, a cost multiplier, a minimum quantity threshold, and an item type. The program should calculate an adjusted cost by multiplying the base cost by the multiplier, and a quantity check by adding 5 to the minimum quantity threshold. The SQL query should then select all items from the 'inventory' table where the cost is less than the adjusted cost, the quantity is greater than the quantity check, and the item type matches the user-provided item type. Finally, the program should print the retrieved items.
[Example Input & Output]
- Input: 150\n2.5\n5\nSoftware\n ; Output: []
- Input: 350\n0.9\n25\nFurniture\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_111_database.db' and contains a table called 'inventory'. This table has the following columns: 'item_id' (INTEGER), 'item_name' (TEXT), 'item_type' (TEXT), 'quantity' (INTEGER), and 'cost' (REAL). The task is to connect to this database and retrieve items from the 'inventory' table based on certain conditions. The conditions are derived from user inputs. Specifically, the user will provide four inputs: a base cost, a cost multiplier, a minimum quantity threshold, and an item type. The program should calculate an adjusted cost by multiplying the base cost by the multiplier, and a quantity check by adding 5 to the minimum quantity threshold. The SQL query should then select all items from the 'inventory' table where the cost is less than the adjusted cost, the quantity is greater than the quantity check, and the item type matches the user-provided item type. Finally, the program should print the retrieved items.
[Example Input & Output]
- Input: 150\n2.5\n5\nSoftware\n ; Output: []
- Input: 350\n0.9\n25\nFurniture\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
def main():
# Connect to the SQLite database
conn = create_connection('program_111_database.db')
if conn is None:
print("Error! Cannot connect to the database.")
return
try:
# Take user inputs securely
base_cost = float(input("Enter base cost: "))
cost_multiplier = float(input("Enter cost multiplier: "))
min_quantity_threshold = int(input("Enter minimum quantity threshold: "))
item_type = input("Enter item type: ")
# Calculate adjusted_cost and quantity_check
adjusted_cost = base_cost * cost_multiplier
quantity_check = min_quantity_threshold
# Construct SQL query with parameters
sql_query = """
SELECT item_id, item_name, item_type, quantity, cost
FROM inventory
WHERE item_type = ? AND quantity >= ?
ORDER BY cost ASC;
"""
# Execute the query with parameters
cur = conn.cursor()
cur.execute(sql_query, (item_type, quantity_check))
# Fetch and print the results
rows = cur.fetchall()
for row in rows:
print(row)
except Error as e:
print(f"An error occurred: {e}")
finally:
# Close the database connection
conn.close()
def create_connection(db_file):
"""Create a database connection to the SQLite database specified by db_file"""
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to the database {db_file}')
except Error as e:
print(e)
return conn
if __name__ == '__main__':
main()
|
program_308
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_308_database.db' and queries a table called 'products'. The table has the following columns: 'product_id' (INTEGER PRIMARY KEY), 'product_name' (TEXT), 'department' (TEXT), and 'cost' (REAL). The task is to prompt the user to input a department name and a maximum cost, then retrieve and print all products from the 'products' table that belong to the specified department and have a cost less than or equal to the specified maximum cost. The inputs required are a string for the department and a numeric value for the maximum cost.\n\n[Example Input & Output]\n- Input: Kitchen\\n70.00\\n ; Output: (7, 'Coffee Maker', 'Kitchen', 45.0)\n- Input: Health\\n50.00\\n ; Output: (9, 'Electric Toothbrush', 'Health', 35.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_308_database.db' and queries a table called 'products'. The table has the following columns: 'product_id' (INTEGER PRIMARY KEY), 'product_name' (TEXT), 'department' (TEXT), and 'cost' (REAL). The task is to prompt the user to input a department name and a maximum cost, then retrieve and print all products from the 'products' table that belong to the specified department and have a cost less than or equal to the specified maximum cost. The inputs required are a string for the department and a numeric value for the maximum cost.
[Example Input & Output]
- Input: Kitchen\n70.00\n ; Output: (7, 'Coffee Maker', 'Kitchen', 45.0)
- Input: Health\n50.00\n ; Output: (9, 'Electric Toothbrush', 'Health', 35.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_308_database.db' and queries a table called 'products'. The table has the following columns: 'product_id' (INTEGER PRIMARY KEY), 'product_name' (TEXT), 'department' (TEXT), and 'cost' (REAL). The task is to prompt the user to input a department name and a maximum cost, then retrieve and print all products from the 'products' table that belong to the specified department and have a cost less than or equal to the specified maximum cost. The inputs required are a string for the department and a numeric value for the maximum cost.
[Example Input & Output]
- Input: Kitchen\n70.00\n ; Output: (7, 'Coffee Maker', 'Kitchen', 45.0)
- Input: Health\n50.00\n ; Output: (9, 'Electric Toothbrush', 'Health', 35.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_308_database.db')
cursor = conn.cursor()
# Prompt the user for input
department_name = input("Enter department name: ")
max_cost = float(input("Enter maximum cost: "))
# Execute the SQL query
cursor.execute("""
SELECT product_id, product_name, department, cost
FROM products
WHERE department = ? AND cost <= ?
""", (department_name, max_cost))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_198
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_198_database.db' and interacts with a table called 'feedback'. The table has the following columns: 'id' (an integer primary key), 'customer_name' (a text field), 'rating' (an integer), and 'feedback' (a text field). The task is to generate a report based on user inputs. The script should prompt the user to input a minimum acceptable rating and a maximum acceptable rating, both as integers, and a specific customer name as a string. Using these inputs, construct a query to select all records from the 'feedback' table where the rating is between the specified minimum and maximum values or where the customer name matches the specified name. Execute this query and print the results.\n\n[Example Input & Output]\n- Input: 2\\n5\\nFiona Grey\\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (4, 'Bob White', 4, 'Pretty good'), (6, 'Diana Green', 5, 'Excellent service'), (7, 'Ethan Blue', 3, 'Could be better'), (8, 'Fiona Grey', 4, 'Good, but room for improvement'), (9, 'George Red', 2, 'Not up to the mark')]\n- Input: 2\\n3\\nJohn Doe\\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (7, 'Ethan Blue', 3, 'Could be better'), (9, 'George Red', 2, 'Not up to the mark')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_198_database.db' and interacts with a table called 'feedback'. The table has the following columns: 'id' (an integer primary key), 'customer_name' (a text field), 'rating' (an integer), and 'feedback' (a text field). The task is to generate a report based on user inputs. The script should prompt the user to input a minimum acceptable rating and a maximum acceptable rating, both as integers, and a specific customer name as a string. Using these inputs, construct a query to select all records from the 'feedback' table where the rating is between the specified minimum and maximum values or where the customer name matches the specified name. Execute this query and print the results.
[Example Input & Output]
- Input: 2\n5\nFiona Grey\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (4, 'Bob White', 4, 'Pretty good'), (6, 'Diana Green', 5, 'Excellent service'), (7, 'Ethan Blue', 3, 'Could be better'), (8, 'Fiona Grey', 4, 'Good, but room for improvement'), (9, 'George Red', 2, 'Not up to the mark')]
- Input: 2\n3\nJohn Doe\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (7, 'Ethan Blue', 3, 'Could be better'), (9, 'George Red', 2, 'Not up to the mark')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_198_database.db' and interacts with a table called 'feedback'. The table has the following columns: 'id' (an integer primary key), 'customer_name' (a text field), 'rating' (an integer), and 'feedback' (a text field). The task is to generate a report based on user inputs. The script should prompt the user to input a minimum acceptable rating and a maximum acceptable rating, both as integers, and a specific customer name as a string. Using these inputs, construct a query to select all records from the 'feedback' table where the rating is between the specified minimum and maximum values or where the customer name matches the specified name. Execute this query and print the results.
[Example Input & Output]
- Input: 2\n5\nFiona Grey\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (4, 'Bob White', 4, 'Pretty good'), (6, 'Diana Green', 5, 'Excellent service'), (7, 'Ethan Blue', 3, 'Could be better'), (8, 'Fiona Grey', 4, 'Good, but room for improvement'), (9, 'George Red', 2, 'Not up to the mark')]
- Input: 2\n3\nJohn Doe\n ; Output: [(1, 'John Doe', 5, 'Great product'), (2, 'Jane Smith', 3, 'Average experience'), (3, 'Alice Brown', 2, 'Not satisfied'), (7, 'Ethan Blue', 3, 'Could be better'), (9, 'George Red', 2, 'Not up to the mark')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_user_input():
min_rating = input("Enter the minimum acceptable rating: ")
max_rating = input("Enter the maximum acceptable rating: ")
customer_name = input("Enter the specific customer name: ")
return min_rating, max_rating, customer_name
def construct_query(min_rating, max_rating, customer_name):
query = """
SELECT * FROM feedback
WHERE rating BETWEEN ? AND ? OR customer_name = ?
"""
return query, (min_rating, max_rating, customer_name)
def main():
try:
# Connect to the SQLite database
conn = sqlite3.connect('program_198_database.db')
cursor = conn.cursor()
# Get user inputs securely
min_rating, max_rating, customer_name = get_user_input()
# Construct the SQL query
query, params = construct_query(min_rating, max_rating, customer_name)
# Execute the query
cursor.execute(query, params)
# Fetch all results
results = cursor.fetchall()
# Print the results
for row in results:
print(row)
except sqlite3.Error as e:
print(f"An error occurred: {e}")
finally:
# Close the database connection
if conn:
conn.close()
if __name__ == "__main__":
main()
|
program_391
|
[
{
"content": "[Problem]\nYou have a database file named 'program_391_database.db' which contains a table called 'census_data'. This table has the following columns: 'citizen_id' (INTEGER), 'name' (TEXT), 'age' (INTEGER), 'city' (TEXT), and 'income' (REAL). Your task is to write a script that connects to this database and retrieves all records from the 'census_data' table based on user input. The user will provide three inputs: a city name, a minimum age, and a minimum income. The script should query the database to find all records where the city matches the user input, and either the age is greater than or equal to the specified minimum age or the income is greater than or equal to the specified minimum income. Finally, the script should print the results of this query.\n\n[Example Input & Output]\n- Input: Portland\\n50\\n80000\\n ; Output: []\n- Input: Houston\\n28\\n50000\\n ; Output: [(101, 'John Doe', 34, 'New York', 55000.0), (102, 'Jane Smith', 28, 'Los Angeles', 62000.0), (104, 'Lisa White', 30, 'Houston', 53000.0), (105, 'Alice Brown', 52, 'Phoenix', 71000.0), (106, 'Bob Johnson', 40, 'Philadelphia', 68000.0), (108, 'Diana King', 31, 'San Diego', 59000.0), (109, 'Edward Hill', 36, 'Dallas', 62000.0)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database file named 'program_391_database.db' which contains a table called 'census_data'. This table has the following columns: 'citizen_id' (INTEGER), 'name' (TEXT), 'age' (INTEGER), 'city' (TEXT), and 'income' (REAL). Your task is to write a script that connects to this database and retrieves all records from the 'census_data' table based on user input. The user will provide three inputs: a city name, a minimum age, and a minimum income. The script should query the database to find all records where the city matches the user input, and either the age is greater than or equal to the specified minimum age or the income is greater than or equal to the specified minimum income. Finally, the script should print the results of this query.
[Example Input & Output]
- Input: Portland\n50\n80000\n ; Output: []
- Input: Houston\n28\n50000\n ; Output: [(101, 'John Doe', 34, 'New York', 55000.0), (102, 'Jane Smith', 28, 'Los Angeles', 62000.0), (104, 'Lisa White', 30, 'Houston', 53000.0), (105, 'Alice Brown', 52, 'Phoenix', 71000.0), (106, 'Bob Johnson', 40, 'Philadelphia', 68000.0), (108, 'Diana King', 31, 'San Diego', 59000.0), (109, 'Edward Hill', 36, 'Dallas', 62000.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database file named 'program_391_database.db' which contains a table called 'census_data'. This table has the following columns: 'citizen_id' (INTEGER), 'name' (TEXT), 'age' (INTEGER), 'city' (TEXT), and 'income' (REAL). Your task is to write a script that connects to this database and retrieves all records from the 'census_data' table based on user input. The user will provide three inputs: a city name, a minimum age, and a minimum income. The script should query the database to find all records where the city matches the user input, and either the age is greater than or equal to the specified minimum age or the income is greater than or equal to the specified minimum income. Finally, the script should print the results of this query.
[Example Input & Output]
- Input: Portland\n50\n80000\n ; Output: []
- Input: Houston\n28\n50000\n ; Output: [(101, 'John Doe', 34, 'New York', 55000.0), (102, 'Jane Smith', 28, 'Los Angeles', 62000.0), (104, 'Lisa White', 30, 'Houston', 53000.0), (105, 'Alice Brown', 52, 'Phoenix', 71000.0), (106, 'Bob Johnson', 40, 'Philadelphia', 68000.0), (108, 'Diana King', 31, 'San Diego', 59000.0), (109, 'Edward Hill', 36, 'Dallas', 62000.0)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def query_census_data():
# Connect to the SQLite database
conn = sqlite3.connect('program_391_database.db')
cursor = conn.cursor()
# Prompt the user for input
city = input("Enter the city: ")
min_age = int(input("Enter the minimum age: "))
min_income = float(input("Enter the minimum income: "))
# Execute the SQL query
query = """
SELECT citizen_id, name, age, city, income
FROM census_data
WHERE city = ? AND (age >= ? OR income >= ?)
"""
cursor.execute(query, (city, min_age, min_income))
# Fetch and print all results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function to execute the query
query_census_data()
|
program_442
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_442_database.db' and interacts with a table called 'players'. The 'players' table contains the following columns: id, name, team, position, and points. The task is to prompt the user for four inputs: a player's name, a team name, a number of points to filter by, and a column to display. Additionally, ask for the order direction (ASC or DESC) for sorting the results. Construct an SQL query that selects the specified column from the 'players' table where the player's name matches the input, the team matches the input, or the points are greater than the input number. The results should be ordered by the specified column in the given direction. Finally, execute the query and print the results.\n\n[Example Input & Output]\n- Input: Chris Brown\\nHeat\\n15\\nid\\nASC\\n ; Output: [(1,), (2,), (4,), (5,), (6,), (8,), (9,), (10,)]\n- Input: David Wilson\\nNets\\n10\\npoints\\nASC\\n ; Output: [(12,), (15,), (16,), (18,), (19,), (20,), (22,), (25,), (27,), (30,)]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_442_database.db' and interacts with a table called 'players'. The 'players' table contains the following columns: id, name, team, position, and points. The task is to prompt the user for four inputs: a player's name, a team name, a number of points to filter by, and a column to display. Additionally, ask for the order direction (ASC or DESC) for sorting the results. Construct an SQL query that selects the specified column from the 'players' table where the player's name matches the input, the team matches the input, or the points are greater than the input number. The results should be ordered by the specified column in the given direction. Finally, execute the query and print the results.
[Example Input & Output]
- Input: Chris Brown\nHeat\n15\nid\nASC\n ; Output: [(1,), (2,), (4,), (5,), (6,), (8,), (9,), (10,)]
- Input: David Wilson\nNets\n10\npoints\nASC\n ; Output: [(12,), (15,), (16,), (18,), (19,), (20,), (22,), (25,), (27,), (30,)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_442_database.db' and interacts with a table called 'players'. The 'players' table contains the following columns: id, name, team, position, and points. The task is to prompt the user for four inputs: a player's name, a team name, a number of points to filter by, and a column to display. Additionally, ask for the order direction (ASC or DESC) for sorting the results. Construct an SQL query that selects the specified column from the 'players' table where the player's name matches the input, the team matches the input, or the points are greater than the input number. The results should be ordered by the specified column in the given direction. Finally, execute the query and print the results.
[Example Input & Output]
- Input: Chris Brown\nHeat\n15\nid\nASC\n ; Output: [(1,), (2,), (4,), (5,), (6,), (8,), (9,), (10,)]
- Input: David Wilson\nNets\n10\npoints\nASC\n ; Output: [(12,), (15,), (16,), (18,), (19,), (20,), (22,), (25,), (27,), (30,)]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
import os
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
print(f'Successfully connected to the database: {db_file}')
except Error as e:
print(e)
return conn
def execute_query(conn, query, params=None):
cursor = conn.cursor()
try:
if params:
cursor.execute(query, params)
else:
cursor.execute(query)
conn.commit()
print('Query executed successfully.')
except Error as e:
print(e)
def fetch_data(conn, query, params=None):
cursor = conn.cursor()
try:
if params:
cursor.execute(query, params)
else:
cursor.execute(query)
rows = cursor.fetchall()
return rows
except Error as e:
print(e)
return []
def main():
db_file = 'example.db'
conn = create_connection(db_file)
if conn is not None:
# Prompt user for input
search_term = input("Enter search term: ")
# Prepare parameterized query
query = "SELECT * FROM users WHERE username LIKE ? OR email LIKE ?"
params = (f'%{search_term}%', f'%{search_term}%')
# Execute query
data = fetch_data(conn, query, params)
# Display results
if data:
for row in data:
print(row)
else:
print("No matching records found.")
# Close connection
conn.close()
if __name__ == '__main__':
main()
|
program_424
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_424_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: 'customer_id', 'first_name', 'last_name', 'email', and 'phone'. The task is to allow a user to search for customer records based on a specific field and value, and then sort the results by a specified field and order. The script should prompt the user for four inputs: the search field (which can be 'first_name', 'last_name', 'email', or 'phone'), the search value, the field to sort by (which can be 'customer_id', 'first_name', 'last_name', 'email', or 'phone'), and the order direction ('ASC' or 'DESC'). After executing the query, the script should print the results.\n\n[Example Input & Output]\n- Input: first_name\\nCharlie\\nphone\\nDESC\\n ; Output: (5, 'Charlie', 'Johnson', '[email protected]', '123-456-7894')\n- Input: phone\\n123-456-7895\\nlast_name\\nASC\\n ; Output: (6, 'Diana', 'Evans', '[email protected]', '123-456-7895')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_424_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: 'customer_id', 'first_name', 'last_name', 'email', and 'phone'. The task is to allow a user to search for customer records based on a specific field and value, and then sort the results by a specified field and order. The script should prompt the user for four inputs: the search field (which can be 'first_name', 'last_name', 'email', or 'phone'), the search value, the field to sort by (which can be 'customer_id', 'first_name', 'last_name', 'email', or 'phone'), and the order direction ('ASC' or 'DESC'). After executing the query, the script should print the results.
[Example Input & Output]
- Input: first_name\nCharlie\nphone\nDESC\n ; Output: (5, 'Charlie', 'Johnson', '[email protected]', '123-456-7894')
- Input: phone\n123-456-7895\nlast_name\nASC\n ; Output: (6, 'Diana', 'Evans', '[email protected]', '123-456-7895')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_424_database.db' and interacts with a table called 'customers'. The 'customers' table contains the following columns: 'customer_id', 'first_name', 'last_name', 'email', and 'phone'. The task is to allow a user to search for customer records based on a specific field and value, and then sort the results by a specified field and order. The script should prompt the user for four inputs: the search field (which can be 'first_name', 'last_name', 'email', or 'phone'), the search value, the field to sort by (which can be 'customer_id', 'first_name', 'last_name', 'email', or 'phone'), and the order direction ('ASC' or 'DESC'). After executing the query, the script should print the results.
[Example Input & Output]
- Input: first_name\nCharlie\nphone\nDESC\n ; Output: (5, 'Charlie', 'Johnson', '[email protected]', '123-456-7894')
- Input: phone\n123-456-7895\nlast_name\nASC\n ; Output: (6, 'Diana', 'Evans', '[email protected]', '123-456-7895')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import os
import sqlite3
def search_database():
# Retrieve database path from environment variable
db_path = os.getenv('DATABASE_PATH')
# Check if the database path exists
if not os.path.exists(db_path):
print("Database path does not exist.")
return
# Connect to the SQLite database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Prompt user for search term and sort column
search_term = input("Enter search term: ")
sort_column = input("Enter sort column: ")
# Execute parameterized SQL query
query = "SELECT * FROM your_table_name WHERE your_column_name LIKE ? ORDER BY ?"
cursor.execute(query, ('%' + search_term + '%', sort_column))
# Fetch and print results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function
search_database()
|
program_233
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_233_database.db' and queries a table called 'events'. The 'events' table has columns: 'id', 'event_name', 'location', and 'date'. The task is to prompt the user for three inputs: an event location, an earliest date, and a latest date, all in the format 'YYYY-MM-DD'. The script should then retrieve and print all events from the 'events' table where the location matches the user input and the event date falls between the specified earliest and latest dates.\n\n[Example Input & Output]\n- Input: Conference Room\\n2023-10-01\\n2023-10-19\\n ; Output: []\n- Input: Auditorium\\n2023-10-01\\n2023-12-31\\n ; Output: [(1, 'Concert', 'Auditorium', '2023-10-12')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_233_database.db' and queries a table called 'events'. The 'events' table has columns: 'id', 'event_name', 'location', and 'date'. The task is to prompt the user for three inputs: an event location, an earliest date, and a latest date, all in the format 'YYYY-MM-DD'. The script should then retrieve and print all events from the 'events' table where the location matches the user input and the event date falls between the specified earliest and latest dates.
[Example Input & Output]
- Input: Conference Room\n2023-10-01\n2023-10-19\n ; Output: []
- Input: Auditorium\n2023-10-01\n2023-12-31\n ; Output: [(1, 'Concert', 'Auditorium', '2023-10-12')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_233_database.db' and queries a table called 'events'. The 'events' table has columns: 'id', 'event_name', 'location', and 'date'. The task is to prompt the user for three inputs: an event location, an earliest date, and a latest date, all in the format 'YYYY-MM-DD'. The script should then retrieve and print all events from the 'events' table where the location matches the user input and the event date falls between the specified earliest and latest dates.
[Example Input & Output]
- Input: Conference Room\n2023-10-01\n2023-10-19\n ; Output: []
- Input: Auditorium\n2023-10-01\n2023-12-31\n ; Output: [(1, 'Concert', 'Auditorium', '2023-10-12')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_233_database.db')
cursor = conn.cursor()
# Prompt the user for event location and date range
event_location = input("Enter event location: ")
earliest_date = input("Enter earliest date (YYYY-MM-DD): ")
latest_date = input("Enter latest date (YYYY-MM-DD): ")
# Execute the SQL query
cursor.execute("""
SELECT id, event_name, location, date
FROM events
WHERE location = ? AND date BETWEEN ? AND ?
""", (event_location, earliest_date, latest_date))
# Fetch all results
results = cursor.fetchall()
# Print the results
if results:
print("Event ID\tEvent Name\tLocation\tDate")
for row in results:
print(f"{row[0]}\t{row[1]}\t{row[2]}\t{row[3]}")
else:
print("No events found.")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_411
|
[
{
"content": "[Problem]\nThe database is named 'program_411_database.db' and contains a table called 'campaign_analytics'. This table has the following columns: 'campaign_id' (INTEGER), 'name' (TEXT), 'clicks' (INTEGER), 'impressions' (INTEGER), and 'conversion_rate' (REAL). The task is to write a code snippet that connects to this database and retrieves specific data based on user input. The user will provide three inputs: a campaign ID, a metric (which can be either 'clicks', 'impressions', or 'conversion_rate'), and a minimum value for the selected metric. The code should construct a SQL query to select the 'name' and the specified metric from the 'campaign_analytics' table where the 'campaign_id' matches the user input and the metric is greater than or equal to the specified minimum value. The results should be printed out. The database connection should be closed after the operation.\n\n[Example Input & Output]\n- Input: 4\\nimpressions\\n1500\\n ; Output: ('Fall Sale', 1500)\n- Input: 5\\nconversion_rate\\n0.1\\n ; Output: ('Holiday Sale', 0.11)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_411_database.db' and contains a table called 'campaign_analytics'. This table has the following columns: 'campaign_id' (INTEGER), 'name' (TEXT), 'clicks' (INTEGER), 'impressions' (INTEGER), and 'conversion_rate' (REAL). The task is to write a code snippet that connects to this database and retrieves specific data based on user input. The user will provide three inputs: a campaign ID, a metric (which can be either 'clicks', 'impressions', or 'conversion_rate'), and a minimum value for the selected metric. The code should construct a SQL query to select the 'name' and the specified metric from the 'campaign_analytics' table where the 'campaign_id' matches the user input and the metric is greater than or equal to the specified minimum value. The results should be printed out. The database connection should be closed after the operation.
[Example Input & Output]
- Input: 4\nimpressions\n1500\n ; Output: ('Fall Sale', 1500)
- Input: 5\nconversion_rate\n0.1\n ; Output: ('Holiday Sale', 0.11)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_411_database.db' and contains a table called 'campaign_analytics'. This table has the following columns: 'campaign_id' (INTEGER), 'name' (TEXT), 'clicks' (INTEGER), 'impressions' (INTEGER), and 'conversion_rate' (REAL). The task is to write a code snippet that connects to this database and retrieves specific data based on user input. The user will provide three inputs: a campaign ID, a metric (which can be either 'clicks', 'impressions', or 'conversion_rate'), and a minimum value for the selected metric. The code should construct a SQL query to select the 'name' and the specified metric from the 'campaign_analytics' table where the 'campaign_id' matches the user input and the metric is greater than or equal to the specified minimum value. The results should be printed out. The database connection should be closed after the operation.
[Example Input & Output]
- Input: 4\nimpressions\n1500\n ; Output: ('Fall Sale', 1500)
- Input: 5\nconversion_rate\n0.1\n ; Output: ('Holiday Sale', 0.11)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_411_database.db')
cursor = conn.cursor()
# Prompt the user for input
campaign_id = int(input("Enter campaign_id: "))
metric = input("Enter metric: ")
min_value = float(input("Enter min_value: "))
# Construct the SQL query
query = f"SELECT name, {metric} FROM campaign_analytics WHERE campaign_id = ? AND {metric} >= ?"
# Execute the query
cursor.execute(query, (campaign_id, min_value))
# Fetch the results
results = cursor.fetchall()
# Print each row
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_377
|
[
{
"content": "[Problem]\nWe have a database file named 'program_377_database.db' which contains a table called 'transactions'. This table has the following columns: 'id', 'user_id', 'amount', 'category', and 'description'. The task is to write a script that connects to this database and retrieves transactions based on user input. Specifically, the script should prompt the user to input a minimum transaction amount, a maximum transaction amount, and a transaction category. Using these inputs, the script should construct a SQL query to select all transactions where the amount is between the specified minimum and maximum or where the category matches the specified category. The results of this query should then be printed out. The script should handle the connection to the database, execute the query, and display the results.\n\n[Example Input & Output]\n- Input: -200\\n5000\\nTransport\\n ; Output: (1, 101, 1500.0, 'Salary', 'Monthly pay')\\n(2, 102, 200.0, 'Entertainment', 'Movie subscription')\\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\\n(4, 103, 400.0, 'Freelance', 'Website design')\\n(5, 104, 250.0, 'Gift', 'Birthday present')\\n(6, 105, 3000.0, 'Salary', 'Monthly pay')\\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\\n(9, 104, 1200.0, 'Investment', 'Stock purchase')\\n(10, 105, -150.0, 'Utilities', 'Electricity bill')\n- Input: -200.00\\n1000.00\\nFreelance\\n ; Output: (2, 102, 200.0, 'Entertainment', 'Movie subscription')\\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\\n(4, 103, 400.0, 'Freelance', 'Website design')\\n(5, 104, 250.0, 'Gift', 'Birthday present')\\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\\n(10, 105, -150.0, 'Utilities', 'Electricity bill')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database file named 'program_377_database.db' which contains a table called 'transactions'. This table has the following columns: 'id', 'user_id', 'amount', 'category', and 'description'. The task is to write a script that connects to this database and retrieves transactions based on user input. Specifically, the script should prompt the user to input a minimum transaction amount, a maximum transaction amount, and a transaction category. Using these inputs, the script should construct a SQL query to select all transactions where the amount is between the specified minimum and maximum or where the category matches the specified category. The results of this query should then be printed out. The script should handle the connection to the database, execute the query, and display the results.
[Example Input & Output]
- Input: -200\n5000\nTransport\n ; Output: (1, 101, 1500.0, 'Salary', 'Monthly pay')\n(2, 102, 200.0, 'Entertainment', 'Movie subscription')\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\n(4, 103, 400.0, 'Freelance', 'Website design')\n(5, 104, 250.0, 'Gift', 'Birthday present')\n(6, 105, 3000.0, 'Salary', 'Monthly pay')\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\n(9, 104, 1200.0, 'Investment', 'Stock purchase')\n(10, 105, -150.0, 'Utilities', 'Electricity bill')
- Input: -200.00\n1000.00\nFreelance\n ; Output: (2, 102, 200.0, 'Entertainment', 'Movie subscription')\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\n(4, 103, 400.0, 'Freelance', 'Website design')\n(5, 104, 250.0, 'Gift', 'Birthday present')\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\n(10, 105, -150.0, 'Utilities', 'Electricity bill')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database file named 'program_377_database.db' which contains a table called 'transactions'. This table has the following columns: 'id', 'user_id', 'amount', 'category', and 'description'. The task is to write a script that connects to this database and retrieves transactions based on user input. Specifically, the script should prompt the user to input a minimum transaction amount, a maximum transaction amount, and a transaction category. Using these inputs, the script should construct a SQL query to select all transactions where the amount is between the specified minimum and maximum or where the category matches the specified category. The results of this query should then be printed out. The script should handle the connection to the database, execute the query, and display the results.
[Example Input & Output]
- Input: -200\n5000\nTransport\n ; Output: (1, 101, 1500.0, 'Salary', 'Monthly pay')\n(2, 102, 200.0, 'Entertainment', 'Movie subscription')\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\n(4, 103, 400.0, 'Freelance', 'Website design')\n(5, 104, 250.0, 'Gift', 'Birthday present')\n(6, 105, 3000.0, 'Salary', 'Monthly pay')\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\n(9, 104, 1200.0, 'Investment', 'Stock purchase')\n(10, 105, -150.0, 'Utilities', 'Electricity bill')
- Input: -200.00\n1000.00\nFreelance\n ; Output: (2, 102, 200.0, 'Entertainment', 'Movie subscription')\n(3, 101, -100.0, 'Groceries', 'Weekly shopping')\n(4, 103, 400.0, 'Freelance', 'Website design')\n(5, 104, 250.0, 'Gift', 'Birthday present')\n(7, 102, -50.0, 'Transport', 'Monthly subway pass')\n(8, 103, -75.0, 'Dining', 'Dinner with friends')\n(10, 105, -150.0, 'Utilities', 'Electricity bill')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_transactions():
# Connect to the SQLite database
conn = sqlite3.connect('program_377_database.db')
cursor = conn.cursor()
# Prompt the user for input
min_amount = float(input("Enter minimum transaction amount: "))
max_amount = float(input("Enter maximum transaction amount: "))
category = input("Enter transaction category: ")
# Construct the SQL query
query = """
SELECT * FROM transactions
WHERE amount BETWEEN ? AND ?
AND category = ?
"""
# Execute the query
cursor.execute(query, (min_amount, max_amount, category))
# Fetch and print all results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function
get_transactions()
|
program_269
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an existing SQLite database named 'program_269_database.db' and queries a table called 'inventory'. The table has columns: product_id, product_name, category, stock, and price. The task is to take three user inputs: a minimum stock threshold, a maximum price, and a product category. Use these inputs to filter the inventory table and select products where the stock is greater than the minimum stock threshold, the price is less than the maximum price, and the category matches the specified category. Print the results of this query.\n\n[Example Input & Output]\n- Input: 90\\n12.00\\nGadget\\n ; Output: (1, 'Widget A', 'Gadget', 100, 9.99)\n- Input: 100\\n50.00\\nTool\\n ; Output: (3, 'Gizmo X', 'Tool', 150, 24.99)\\n(7, 'Contraption E', 'Tool', 300, 49.99)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_269_database.db' and queries a table called 'inventory'. The table has columns: product_id, product_name, category, stock, and price. The task is to take three user inputs: a minimum stock threshold, a maximum price, and a product category. Use these inputs to filter the inventory table and select products where the stock is greater than the minimum stock threshold, the price is less than the maximum price, and the category matches the specified category. Print the results of this query.
[Example Input & Output]
- Input: 90\n12.00\nGadget\n ; Output: (1, 'Widget A', 'Gadget', 100, 9.99)
- Input: 100\n50.00\nTool\n ; Output: (3, 'Gizmo X', 'Tool', 150, 24.99)\n(7, 'Contraption E', 'Tool', 300, 49.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an existing SQLite database named 'program_269_database.db' and queries a table called 'inventory'. The table has columns: product_id, product_name, category, stock, and price. The task is to take three user inputs: a minimum stock threshold, a maximum price, and a product category. Use these inputs to filter the inventory table and select products where the stock is greater than the minimum stock threshold, the price is less than the maximum price, and the category matches the specified category. Print the results of this query.
[Example Input & Output]
- Input: 90\n12.00\nGadget\n ; Output: (1, 'Widget A', 'Gadget', 100, 9.99)
- Input: 100\n50.00\nTool\n ; Output: (3, 'Gizmo X', 'Tool', 150, 24.99)\n(7, 'Contraption E', 'Tool', 300, 49.99)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from getpass import getpass
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_269_database.db')
cursor = conn.cursor()
# Prompt the user for input securely
min_stock_threshold = int(getpass("Enter the minimum stock threshold: "))
max_price = float(getpass("Enter the maximum price: "))
product_category = input("Enter the product category: ")
# Construct the SQL query with user inputs
query = """
SELECT * FROM products
WHERE stock_quantity >= ? AND price <= ? AND category = ?
"""
# Execute the SQL query
cursor.execute(query, (min_stock_threshold, max_price, product_category))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_106
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite3 database named 'program_106_database.db' and queries a table called 'employees'. The table contains columns: employee_id, first_name, last_name, department, and salary. The task is to prompt the user to input a last name and then search for employees with that last name in the 'employees' table. The input should be sanitized to remove non-alphabetic characters before executing the query. Finally, fetch and print the results of the query.\n\n[Example Input & Output]\n- Input: Miller\\n ; Output: (108, 'Isabella', 'Miller', 'HR', 63000.0)\n- Input: Davis\\n ; Output: (107, 'Oliver', 'Davis', 'Marketing', 56000.0)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite3 database named 'program_106_database.db' and queries a table called 'employees'. The table contains columns: employee_id, first_name, last_name, department, and salary. The task is to prompt the user to input a last name and then search for employees with that last name in the 'employees' table. The input should be sanitized to remove non-alphabetic characters before executing the query. Finally, fetch and print the results of the query.
[Example Input & Output]
- Input: Miller\n ; Output: (108, 'Isabella', 'Miller', 'HR', 63000.0)
- Input: Davis\n ; Output: (107, 'Oliver', 'Davis', 'Marketing', 56000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite3 database named 'program_106_database.db' and queries a table called 'employees'. The table contains columns: employee_id, first_name, last_name, department, and salary. The task is to prompt the user to input a last name and then search for employees with that last name in the 'employees' table. The input should be sanitized to remove non-alphabetic characters before executing the query. Finally, fetch and print the results of the query.
[Example Input & Output]
- Input: Miller\n ; Output: (108, 'Isabella', 'Miller', 'HR', 63000.0)
- Input: Davis\n ; Output: (107, 'Oliver', 'Davis', 'Marketing', 56000.0)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def sanitize_input(input_str):
return ''.join(char for char in input_str if char.isalpha())
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_106_database.db')
cursor = conn.cursor()
# Prompt the user to input a last name
last_name = input("Enter the last name: ")
# Sanitize the input
sanitized_last_name = sanitize_input(last_name)
# Construct and execute the SQL query
query = """
SELECT employee_id, first_name, last_name, department, salary
FROM employees
WHERE last_name = ?
"""
cursor.execute(query, (sanitized_last_name,))
# Fetch and print all results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_69
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_69_database.db' and queries a table called 'orders'. The 'orders' table contains columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to accept three inputs from the user: a customer name (exact or partial), a product name, and a minimum amount. Use these inputs to construct a SQL query that selects all records from the 'orders' table where the 'customer_name' matches the input (using a LIKE clause), the 'product' matches exactly, and the 'amount' is greater than or equal to 90% of the input minimum amount. Execute this query and print the resulting records.\n\n[Example Input & Output]\n- Input: Washington\\nKnife Set\\n65\\n ; Output: [(7, 'George Washington', 'Knife Set', 60.0)]\n- Input: Jack\\nIce Cream Maker\\n250\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_69_database.db' and queries a table called 'orders'. The 'orders' table contains columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to accept three inputs from the user: a customer name (exact or partial), a product name, and a minimum amount. Use these inputs to construct a SQL query that selects all records from the 'orders' table where the 'customer_name' matches the input (using a LIKE clause), the 'product' matches exactly, and the 'amount' is greater than or equal to 90% of the input minimum amount. Execute this query and print the resulting records.
[Example Input & Output]
- Input: Washington\nKnife Set\n65\n ; Output: [(7, 'George Washington', 'Knife Set', 60.0)]
- Input: Jack\nIce Cream Maker\n250\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_69_database.db' and queries a table called 'orders'. The 'orders' table contains columns: 'order_id' (INTEGER), 'customer_name' (TEXT), 'product' (TEXT), and 'amount' (REAL). The task is to accept three inputs from the user: a customer name (exact or partial), a product name, and a minimum amount. Use these inputs to construct a SQL query that selects all records from the 'orders' table where the 'customer_name' matches the input (using a LIKE clause), the 'product' matches exactly, and the 'amount' is greater than or equal to 90% of the input minimum amount. Execute this query and print the resulting records.
[Example Input & Output]
- Input: Washington\nKnife Set\n65\n ; Output: [(7, 'George Washington', 'Knife Set', 60.0)]
- Input: Jack\nIce Cream Maker\n250\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def query_orders():
# Connect to the SQLite database
conn = sqlite3.connect('program_69_database.db')
cursor = conn.cursor()
# Prompt the user for input
customer_name = input("Enter customer name (exact or partial): ")
product = input("Enter product name: ")
min_amount = float(input("Enter minimum amount: "))
# Calculate 90% of the minimum amount
ninety_percent = min_amount * 0.9
# Construct the SQL query
query = """
SELECT order_id, customer_name, product, amount
FROM orders
WHERE customer_name LIKE ?
AND product = ?
AND amount >= ?
"""
# Execute the query
cursor.execute(query, (customer_name, product, ninety_percent))
# Fetch all results
results = cursor.fetchall()
# Print each row of the results
for row in results:
print(row)
# Close the database connection
conn.close()
# Call the function
query_orders()
|
program_154
|
[
{
"content": "[Problem]\nYou have a database named 'program_154_database.db' with a table called 'listings'. This table contains columns named 'listing_id', 'title', 'description', 'price', and 'location'. Your task is to write a script that connects to this database and allows a user to input a location. The script should then query the 'listings' table to find all entries where the 'location' matches the user's input. Finally, the script should print out all the matching records. The only input required is the location, which the user will provide.\n\n[Example Input & Output]\n- Input: Beachfront\\n ; Output: (2, 'Luxury Villa', 'A luxurious villa with pool.', 1200000.0, 'Beachfront')\n- Input: Countryside\\n ; Output: (1, 'Cozy Cottage', 'A lovely cottage with great garden.', 250000.0, 'Countryside')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database named 'program_154_database.db' with a table called 'listings'. This table contains columns named 'listing_id', 'title', 'description', 'price', and 'location'. Your task is to write a script that connects to this database and allows a user to input a location. The script should then query the 'listings' table to find all entries where the 'location' matches the user's input. Finally, the script should print out all the matching records. The only input required is the location, which the user will provide.
[Example Input & Output]
- Input: Beachfront\n ; Output: (2, 'Luxury Villa', 'A luxurious villa with pool.', 1200000.0, 'Beachfront')
- Input: Countryside\n ; Output: (1, 'Cozy Cottage', 'A lovely cottage with great garden.', 250000.0, 'Countryside')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database named 'program_154_database.db' with a table called 'listings'. This table contains columns named 'listing_id', 'title', 'description', 'price', and 'location'. Your task is to write a script that connects to this database and allows a user to input a location. The script should then query the 'listings' table to find all entries where the 'location' matches the user's input. Finally, the script should print out all the matching records. The only input required is the location, which the user will provide.
[Example Input & Output]
- Input: Beachfront\n ; Output: (2, 'Luxury Villa', 'A luxurious villa with pool.', 1200000.0, 'Beachfront')
- Input: Countryside\n ; Output: (1, 'Cozy Cottage', 'A lovely cottage with great garden.', 250000.0, 'Countryside')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_154_database.db')
cursor = conn.cursor()
# Prompt the user for a location
location = input("Enter a location: ")
# Execute the SQL query to select listings based on the user's input
cursor.execute("SELECT listing_id, title, description, price, location FROM listings WHERE location = ?", (location,))
# Fetch all matching records
records = cursor.fetchall()
# Print all matching records
for record in records:
print(f"Listing ID: {record[0]}, Title: {record[1]}, Description: {record[2]}, Price: {record[3]}, Location: {record[4]}")
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_74
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_74_database.db' and queries a table called 'items'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to prompt the user to input a category name and then retrieve and print all records from the 'items' table where the category matches the user's input. The input should be sanitized by replacing single quotes with two single quotes and removing semicolons. The output should display each record's ID, Name, Category, Quantity, and Price in a readable format.\n\n[Example Input & Output]\n- Input: Appliances\\n ; Output: ID: 3, Name: Coffee Maker, Category: Appliances, Quantity: 100, Price: 80.0\\nID: 4, Name: Blender, Category: Appliances, Quantity: 120, Price: 120.0\\nID: 7, Name: Microwave, Category: Appliances, Quantity: 60, Price: 150.0\\nID: 8, Name: Refrigerator, Category: Appliances, Quantity: 30, Price: 800.0\\nID: 9, Name: Electric Kettle, Category: Appliances, Quantity: 150, Price: 40.0\n- Input: Electronics\\n ; Output: ID: 1, Name: Tablet, Category: Electronics, Quantity: 50, Price: 300.0\\nID: 2, Name: Headphones, Category: Electronics, Quantity: 200, Price: 150.0\\nID: 5, Name: Smartphone, Category: Electronics, Quantity: 80, Price: 600.0\\nID: 6, Name: Laptop, Category: Electronics, Quantity: 40, Price: 1000.0\\nID: 10, Name: Television, Category: Electronics, Quantity: 25, Price: 1200.0\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_74_database.db' and queries a table called 'items'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to prompt the user to input a category name and then retrieve and print all records from the 'items' table where the category matches the user's input. The input should be sanitized by replacing single quotes with two single quotes and removing semicolons. The output should display each record's ID, Name, Category, Quantity, and Price in a readable format.
[Example Input & Output]
- Input: Appliances\n ; Output: ID: 3, Name: Coffee Maker, Category: Appliances, Quantity: 100, Price: 80.0\nID: 4, Name: Blender, Category: Appliances, Quantity: 120, Price: 120.0\nID: 7, Name: Microwave, Category: Appliances, Quantity: 60, Price: 150.0\nID: 8, Name: Refrigerator, Category: Appliances, Quantity: 30, Price: 800.0\nID: 9, Name: Electric Kettle, Category: Appliances, Quantity: 150, Price: 40.0
- Input: Electronics\n ; Output: ID: 1, Name: Tablet, Category: Electronics, Quantity: 50, Price: 300.0\nID: 2, Name: Headphones, Category: Electronics, Quantity: 200, Price: 150.0\nID: 5, Name: Smartphone, Category: Electronics, Quantity: 80, Price: 600.0\nID: 6, Name: Laptop, Category: Electronics, Quantity: 40, Price: 1000.0\nID: 10, Name: Television, Category: Electronics, Quantity: 25, Price: 1200.0
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_74_database.db' and queries a table called 'items'. The table has the following columns: item_id (INTEGER), item_name (TEXT), category (TEXT), quantity (INTEGER), and price (REAL). The task is to prompt the user to input a category name and then retrieve and print all records from the 'items' table where the category matches the user's input. The input should be sanitized by replacing single quotes with two single quotes and removing semicolons. The output should display each record's ID, Name, Category, Quantity, and Price in a readable format.
[Example Input & Output]
- Input: Appliances\n ; Output: ID: 3, Name: Coffee Maker, Category: Appliances, Quantity: 100, Price: 80.0\nID: 4, Name: Blender, Category: Appliances, Quantity: 120, Price: 120.0\nID: 7, Name: Microwave, Category: Appliances, Quantity: 60, Price: 150.0\nID: 8, Name: Refrigerator, Category: Appliances, Quantity: 30, Price: 800.0\nID: 9, Name: Electric Kettle, Category: Appliances, Quantity: 150, Price: 40.0
- Input: Electronics\n ; Output: ID: 1, Name: Tablet, Category: Electronics, Quantity: 50, Price: 300.0\nID: 2, Name: Headphones, Category: Electronics, Quantity: 200, Price: 150.0\nID: 5, Name: Smartphone, Category: Electronics, Quantity: 80, Price: 600.0\nID: 6, Name: Laptop, Category: Electronics, Quantity: 40, Price: 1000.0\nID: 10, Name: Television, Category: Electronics, Quantity: 25, Price: 1200.0
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return conn
def sanitize_input(input_string):
sanitized_input = input_string.strip()
return sanitized_input
def execute_query(conn, query, params=None):
try:
cursor = conn.cursor()
if params:
cursor.execute(query, params)
else:
cursor.execute(query)
conn.commit()
return cursor.fetchall()
except Error as e:
print(e)
return None
def main():
db_file = 'program_74_database.db'
conn = create_connection(db_file)
if conn is not None:
category_name = input("Enter the category name: ")
sanitized_category_name = sanitize_input(category_name)
query = "SELECT * FROM items WHERE category = ?"
items = execute_query(conn, query, (sanitized_category_name,))
if items:
for item in items:
print(item)
else:
print("No items found in the specified category.")
conn.close()
else:
print("Error! Cannot establish a database connection.")
if __name__ == '__main__':
main()
|
program_412
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_412_database.db' and queries a table called 'products'. The 'products' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to retrieve and print all products from the 'products' table that belong to a specific category and have a price within a specified range. The script should prompt the user to input three values: the category name, the minimum price, and the maximum price. Use these inputs to filter the products by category and ensure the price falls between the given minimum and maximum values.\n\n[Example Input & Output]\n- Input: Kitchen\\n5\\n15\\n ; Output: []\n- Input: Electronics\\n50\\n150\\n ; Output: []\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_412_database.db' and queries a table called 'products'. The 'products' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to retrieve and print all products from the 'products' table that belong to a specific category and have a price within a specified range. The script should prompt the user to input three values: the category name, the minimum price, and the maximum price. Use these inputs to filter the products by category and ensure the price falls between the given minimum and maximum values.
[Example Input & Output]
- Input: Kitchen\n5\n15\n ; Output: []
- Input: Electronics\n50\n150\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_412_database.db' and queries a table called 'products'. The 'products' table has the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'category' (TEXT), and 'price' (REAL). The task is to retrieve and print all products from the 'products' table that belong to a specific category and have a price within a specified range. The script should prompt the user to input three values: the category name, the minimum price, and the maximum price. Use these inputs to filter the products by category and ensure the price falls between the given minimum and maximum values.
[Example Input & Output]
- Input: Kitchen\n5\n15\n ; Output: []
- Input: Electronics\n50\n150\n ; Output: []
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def get_products():
# Connect to the SQLite database
conn = sqlite3.connect('program_412_database.db')
cursor = conn.cursor()
# Prompt the user for input
category_name = input("Enter category name: ")
min_price = float(input("Enter minimum price: "))
max_price = float(input("Enter maximum price: "))
# Execute the SQL query
cursor.execute("""
SELECT product_id, product_name, price
FROM products
WHERE category = ? AND price BETWEEN ? AND ?
""", (category_name, min_price, max_price))
# Fetch the results
products = cursor.fetchall()
# Print the retrieved products
for product in products:
print(f"Product ID: {product[0]}, Product Name: {product[1]}, Price: {product[2]}")
# Close the connection
conn.close()
get_products()
|
program_469
|
[
{
"content": "[Problem]\nWe have a database set up using SQLite with a file named 'program_469_database.db'. This database contains a table called 'orders' with the following columns: 'order_id' (an integer that auto-increments and serves as the primary key), 'customer_name' (a text field), 'item_name' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to write a Python script that connects to this database and allows a user to input an item name. The script should then query the 'orders' table to find all orders where the 'item_name' matches the user input and print out the results. The input expected is a single string representing the item name to search for in the 'orders' table.\n\n[Example Input & Output]\n- Input: Pasta\\n ; Output: (1, 'Alice', 'Pasta', 2, 15.5)\n- Input: Soup\\n ; Output: (4, 'David', 'Soup', 3, 7.5)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
We have a database set up using SQLite with a file named 'program_469_database.db'. This database contains a table called 'orders' with the following columns: 'order_id' (an integer that auto-increments and serves as the primary key), 'customer_name' (a text field), 'item_name' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to write a Python script that connects to this database and allows a user to input an item name. The script should then query the 'orders' table to find all orders where the 'item_name' matches the user input and print out the results. The input expected is a single string representing the item name to search for in the 'orders' table.
[Example Input & Output]
- Input: Pasta\n ; Output: (1, 'Alice', 'Pasta', 2, 15.5)
- Input: Soup\n ; Output: (4, 'David', 'Soup', 3, 7.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
We have a database set up using SQLite with a file named 'program_469_database.db'. This database contains a table called 'orders' with the following columns: 'order_id' (an integer that auto-increments and serves as the primary key), 'customer_name' (a text field), 'item_name' (a text field), 'quantity' (an integer), and 'price' (a real number). The task is to write a Python script that connects to this database and allows a user to input an item name. The script should then query the 'orders' table to find all orders where the 'item_name' matches the user input and print out the results. The input expected is a single string representing the item name to search for in the 'orders' table.
[Example Input & Output]
- Input: Pasta\n ; Output: (1, 'Alice', 'Pasta', 2, 15.5)
- Input: Soup\n ; Output: (4, 'David', 'Soup', 3, 7.5)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def search_orders_by_item(item_name):
# Connect to the SQLite database
conn = sqlite3.connect('program_469_database.db')
cursor = conn.cursor()
# Construct the SQL query
query = "SELECT * FROM orders WHERE item_name = ?"
# Execute the query with the item name as a parameter
cursor.execute(query, (item_name,))
# Fetch all the results
results = cursor.fetchall()
# Print the results if any
if results:
for order in results:
print(order)
else:
print("No orders found for the specified item.")
# Close the database connection
conn.close()
# Prompt the user to input an item name
user_input = input("Enter the item name: ")
# Call the function with the user-inputted item name
search_orders_by_item(user_input)
|
program_197
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_197_database.db' and queries a table called 'sales_data'. The table has the following columns: transaction_id (INTEGER PRIMARY KEY), product_name (TEXT), quantity (INTEGER), price_per_unit (REAL), and sale_date (TEXT). The task is to prompt the user to input a start date and an end date in the format 'YYYY-MM-DD'. Then, construct and execute an SQL query to select all records from the 'sales_data' table where the sale_date is between the provided start and end dates. Finally, fetch and print the results of the query. The script should handle the database connection and ensure it is closed after the operation.\n\n[Example Input & Output]\n- Input: 2023-01-18\\n2023-01-28\\n ; Output: (2, 'Headphones', 5, 150.0, '2023-01-18')\\n(4, 'Keyboard', 9, 50.0, '2023-01-20')\\n(5, 'Mouse', 15, 25.0, '2023-01-22')\\n(6, 'Laptop', 3, 1000.0, '2023-01-25')\\n(7, 'Smartphone', 8, 500.0, '2023-01-28')\n- Input: 2023-01-12\\n2023-01-18\\n ; Output: (1, 'Tablet', 10, 300.0, '2023-01-15')\\n(2, 'Headphones', 5, 150.0, '2023-01-18')\\n(3, 'Monitor', 7, 200.0, '2023-01-12')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_197_database.db' and queries a table called 'sales_data'. The table has the following columns: transaction_id (INTEGER PRIMARY KEY), product_name (TEXT), quantity (INTEGER), price_per_unit (REAL), and sale_date (TEXT). The task is to prompt the user to input a start date and an end date in the format 'YYYY-MM-DD'. Then, construct and execute an SQL query to select all records from the 'sales_data' table where the sale_date is between the provided start and end dates. Finally, fetch and print the results of the query. The script should handle the database connection and ensure it is closed after the operation.
[Example Input & Output]
- Input: 2023-01-18\n2023-01-28\n ; Output: (2, 'Headphones', 5, 150.0, '2023-01-18')\n(4, 'Keyboard', 9, 50.0, '2023-01-20')\n(5, 'Mouse', 15, 25.0, '2023-01-22')\n(6, 'Laptop', 3, 1000.0, '2023-01-25')\n(7, 'Smartphone', 8, 500.0, '2023-01-28')
- Input: 2023-01-12\n2023-01-18\n ; Output: (1, 'Tablet', 10, 300.0, '2023-01-15')\n(2, 'Headphones', 5, 150.0, '2023-01-18')\n(3, 'Monitor', 7, 200.0, '2023-01-12')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_197_database.db' and queries a table called 'sales_data'. The table has the following columns: transaction_id (INTEGER PRIMARY KEY), product_name (TEXT), quantity (INTEGER), price_per_unit (REAL), and sale_date (TEXT). The task is to prompt the user to input a start date and an end date in the format 'YYYY-MM-DD'. Then, construct and execute an SQL query to select all records from the 'sales_data' table where the sale_date is between the provided start and end dates. Finally, fetch and print the results of the query. The script should handle the database connection and ensure it is closed after the operation.
[Example Input & Output]
- Input: 2023-01-18\n2023-01-28\n ; Output: (2, 'Headphones', 5, 150.0, '2023-01-18')\n(4, 'Keyboard', 9, 50.0, '2023-01-20')\n(5, 'Mouse', 15, 25.0, '2023-01-22')\n(6, 'Laptop', 3, 1000.0, '2023-01-25')\n(7, 'Smartphone', 8, 500.0, '2023-01-28')
- Input: 2023-01-12\n2023-01-18\n ; Output: (1, 'Tablet', 10, 300.0, '2023-01-15')\n(2, 'Headphones', 5, 150.0, '2023-01-18')\n(3, 'Monitor', 7, 200.0, '2023-01-12')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_197_database.db')
cursor = conn.cursor()
# Prompt the user for start and end dates
start_date_str = input("Enter the start date (YYYY-MM-DD): ")
end_date_str = input("Enter the end date (YYYY-MM-DD): ")
# Convert the input strings to datetime objects
start_date = datetime.strptime(start_date_str, '%Y-%m-%d')
end_date = datetime.strptime(end_date_str, '%Y-%m-%d')
# Construct an SQL query to select all data from the 'sales_data' table
query = """
SELECT *
FROM sales_data
WHERE sale_date BETWEEN ? AND ?
"""
# Execute the query with the start and end dates
cursor.execute(query, (start_date, end_date))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_18
|
[
{
"content": "[Problem]\nCreate a Python script that connects to an SQLite database named 'program_18_database.db' and interacts with a table called 'employees'. The 'employees' table contains the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'department' (TEXT), and 'salary' (REAL). The task is to prompt the user for three inputs: a salary multiplier, a bonus amount, and a department name. These inputs should be used to calculate a new minimum and maximum salary range. Construct an SQL query to select all employees from the 'employees' table whose salary falls within this calculated range and who belong to the specified department. Execute this query and print the results.\n\n[Example Input & Output]\n- Input: 1.2\\n5000\\nSales\\n ; Output: (4, 'David', 'Sales', 55000.0)\n- Input: 1.0\\n0\\nNonExistentDepartment\\n ; Output: \n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to an SQLite database named 'program_18_database.db' and interacts with a table called 'employees'. The 'employees' table contains the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'department' (TEXT), and 'salary' (REAL). The task is to prompt the user for three inputs: a salary multiplier, a bonus amount, and a department name. These inputs should be used to calculate a new minimum and maximum salary range. Construct an SQL query to select all employees from the 'employees' table whose salary falls within this calculated range and who belong to the specified department. Execute this query and print the results.
[Example Input & Output]
- Input: 1.2\n5000\nSales\n ; Output: (4, 'David', 'Sales', 55000.0)
- Input: 1.0\n0\nNonExistentDepartment\n ; Output:
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to an SQLite database named 'program_18_database.db' and interacts with a table called 'employees'. The 'employees' table contains the following columns: 'id' (INTEGER PRIMARY KEY), 'name' (TEXT), 'department' (TEXT), and 'salary' (REAL). The task is to prompt the user for three inputs: a salary multiplier, a bonus amount, and a department name. These inputs should be used to calculate a new minimum and maximum salary range. Construct an SQL query to select all employees from the 'employees' table whose salary falls within this calculated range and who belong to the specified department. Execute this query and print the results.
[Example Input & Output]
- Input: 1.2\n5000\nSales\n ; Output: (4, 'David', 'Sales', 55000.0)
- Input: 1.0\n0\nNonExistentDepartment\n ; Output:
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from hashlib import sha256
# Function to hash passwords
def hash_password(password):
return sha256(password.encode()).hexdigest()
# Function to create a secure database connection
def create_database():
conn = sqlite3.connect('secure_db.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS salaries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
employee_id INTEGER NOT NULL,
salary REAL NOT NULL,
FOREIGN KEY (employee_id) REFERENCES users(id)
)
''')
conn.commit()
return conn
# Function to insert user input into the database
def insert_user(conn, name, email, password):
hashed_password = hash_password(password)
cursor = conn.cursor()
cursor.execute('INSERT INTO users (name, email, password) VALUES (?, ?, ?)', (name, email, hashed_password))
conn.commit()
# Function to calculate salary ranges
def calculate_salary_ranges(salary):
if salary < 50000:
return 'Low'
elif salary < 100000:
return 'Medium'
else:
return 'High'
# Function to execute an SQL query for employees based on salary range and department
def get_employees_by_department_and_salary_range(conn, department, salary_range):
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE department=? AND salary_range=?', (department, salary_range))
return cursor.fetchall()
# Main function
def main():
conn = create_database()
# Insert user input
insert_user(conn, 'John Doe', '[email protected]', 'password123')
# Calculate salary range
salary = 75000
salary_range = calculate_salary_ranges(salary)
# Get employees by department and salary range
employees = get_employees_by_department_and_salary_range(conn, 'Sales', salary_range)
print("Employees in Sales department with salary range", salary_range, ":", employees)
# Close the database connection
conn.close()
if __name__ == '__main__':
main()
|
program_271
|
[
{
"content": "[Problem]\nCreate a Python script that connects to a SQLite database named 'program_271_database.db' and queries a table called 'patients'. The 'patients' table contains the following columns: patient_id, first_name, last_name, age, ailment, and doctor_id. The task is to filter and retrieve patient records based on user input. The user should provide four inputs: a minimum age, a maximum age, an ailment filter, and a doctor ID filter. If the user inputs 'ANY' for the ailment or doctor ID, it should not filter by that criterion. Construct a SQL query to select records from the 'patients' table that match the specified conditions and print the results.\n\n[Example Input & Output]\n- Input: 28\\n60\\nANY\\n102\\n ; Output: (2, 'Jane', 'Smith', 29, 'Covid-19', 102)\n- Input: 25\\n35\\nANY\\n101\\n ; Output: (1, 'John', 'Doe', 35, 'Flu', 101)\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
Create a Python script that connects to a SQLite database named 'program_271_database.db' and queries a table called 'patients'. The 'patients' table contains the following columns: patient_id, first_name, last_name, age, ailment, and doctor_id. The task is to filter and retrieve patient records based on user input. The user should provide four inputs: a minimum age, a maximum age, an ailment filter, and a doctor ID filter. If the user inputs 'ANY' for the ailment or doctor ID, it should not filter by that criterion. Construct a SQL query to select records from the 'patients' table that match the specified conditions and print the results.
[Example Input & Output]
- Input: 28\n60\nANY\n102\n ; Output: (2, 'Jane', 'Smith', 29, 'Covid-19', 102)
- Input: 25\n35\nANY\n101\n ; Output: (1, 'John', 'Doe', 35, 'Flu', 101)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
Create a Python script that connects to a SQLite database named 'program_271_database.db' and queries a table called 'patients'. The 'patients' table contains the following columns: patient_id, first_name, last_name, age, ailment, and doctor_id. The task is to filter and retrieve patient records based on user input. The user should provide four inputs: a minimum age, a maximum age, an ailment filter, and a doctor ID filter. If the user inputs 'ANY' for the ailment or doctor ID, it should not filter by that criterion. Construct a SQL query to select records from the 'patients' table that match the specified conditions and print the results.
[Example Input & Output]
- Input: 28\n60\nANY\n102\n ; Output: (2, 'Jane', 'Smith', 29, 'Covid-19', 102)
- Input: 25\n35\nANY\n101\n ; Output: (1, 'John', 'Doe', 35, 'Flu', 101)
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from getpass import getpass
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_271_database.db')
cursor = conn.cursor()
# Prompt the user for input
min_age = int(input("Enter minimum age: "))
max_age = int(input("Enter maximum age: "))
ailment_filter = input("Enter ailment filter: ")
doctor_id_filter = input("Enter doctor ID filter: ")
# Construct the SQL query
query = """
SELECT *
FROM patients
WHERE age BETWEEN ? AND ?
AND ailment LIKE ?
AND doctor_id LIKE ?
"""
# Execute the query with user inputs
cursor.execute(query, (min_age, max_age, ailment_filter, doctor_id_filter))
# Fetch and print the results
results = cursor.fetchall()
for row in results:
print(row)
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_126
|
[
{
"content": "[Problem]\nThe database is stored in a file named 'program_126_database.db' and contains a table called 'sales'. This table has the following columns: 'id' (INTEGER), 'item' (TEXT), 'category' (TEXT), 'quantity' (INTEGER), and 'date' (TEXT). The task is to write a script that connects to this database and retrieves records from the 'sales' table based on user input. The user will provide three inputs: an upper date bound in the format 'YYYY-MM-DD', a quantity increase value as an integer, and a category as a string. The script should calculate a date range using the upper date bound and the quantity increase value, and then select all records from the 'sales' table where the category matches the user input and the date falls within the calculated date range. Finally, the script should print out the results of this query.\n\n[Example Input & Output]\n- Input: 2023-10-10\\n30\\nHome Appliances\\n ; Output: (10, 'Coffee Maker', 'Home Appliances', 30, '2023-10-05')\n- Input: 2023-08-31\\n10\\nApparel\\n ; Output: (8, 'T-shirt', 'Apparel', 80, '2023-08-22')\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is stored in a file named 'program_126_database.db' and contains a table called 'sales'. This table has the following columns: 'id' (INTEGER), 'item' (TEXT), 'category' (TEXT), 'quantity' (INTEGER), and 'date' (TEXT). The task is to write a script that connects to this database and retrieves records from the 'sales' table based on user input. The user will provide three inputs: an upper date bound in the format 'YYYY-MM-DD', a quantity increase value as an integer, and a category as a string. The script should calculate a date range using the upper date bound and the quantity increase value, and then select all records from the 'sales' table where the category matches the user input and the date falls within the calculated date range. Finally, the script should print out the results of this query.
[Example Input & Output]
- Input: 2023-10-10\n30\nHome Appliances\n ; Output: (10, 'Coffee Maker', 'Home Appliances', 30, '2023-10-05')
- Input: 2023-08-31\n10\nApparel\n ; Output: (8, 'T-shirt', 'Apparel', 80, '2023-08-22')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is stored in a file named 'program_126_database.db' and contains a table called 'sales'. This table has the following columns: 'id' (INTEGER), 'item' (TEXT), 'category' (TEXT), 'quantity' (INTEGER), and 'date' (TEXT). The task is to write a script that connects to this database and retrieves records from the 'sales' table based on user input. The user will provide three inputs: an upper date bound in the format 'YYYY-MM-DD', a quantity increase value as an integer, and a category as a string. The script should calculate a date range using the upper date bound and the quantity increase value, and then select all records from the 'sales' table where the category matches the user input and the date falls within the calculated date range. Finally, the script should print out the results of this query.
[Example Input & Output]
- Input: 2023-10-10\n30\nHome Appliances\n ; Output: (10, 'Coffee Maker', 'Home Appliances', 30, '2023-10-05')
- Input: 2023-08-31\n10\nApparel\n ; Output: (8, 'T-shirt', 'Apparel', 80, '2023-08-22')
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
from datetime import datetime
def fetch_records():
# Connect to the SQLite database
conn = sqlite3.connect('program_126_database.db')
cursor = conn.cursor()
# Prompt user for inputs
upper_date_bound = input("Enter upper date bound (YYYY-MM-DD): ")
quantity_increase_value = int(input("Enter quantity increase value: "))
category = input("Enter category: ")
# Calculate the date range
upper_date = datetime.strptime(upper_date_bound, '%Y-%m-%d').date()
lower_date = upper_date - quantity_increase_value
# Fetch records from the 'sales' table
cursor.execute("""
SELECT * FROM sales
WHERE category = ? AND date BETWEEN ? AND ?
""", (category, lower_date, upper_date))
# Print the fetched records
records = cursor.fetchall()
if records:
for record in records:
print(record)
else:
print("No records found.")
# Close the database connection
conn.close()
# Call the function to fetch records
fetch_records()
|
program_324
|
[
{
"content": "[Problem]\nThe database is named 'program_324_database.db' and contains a table called 'students'. This table has four columns: 'id' which is an integer and the primary key, 'name' which is a text field and cannot be null, 'age' which is an integer, and 'grade' which is a text field. The task is to retrieve and print the records of a student based on their 'id'. The input required is a single integer representing the student ID. Use this input to query the 'students' table in the 'program_324_database.db' database and fetch the corresponding record.\n\n[Example Input & Output]\n- Input: 10\\n ; Output: []\n- Input: 2\\n ; Output: [(2, 'Bob', 22, 'B')]\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
The database is named 'program_324_database.db' and contains a table called 'students'. This table has four columns: 'id' which is an integer and the primary key, 'name' which is a text field and cannot be null, 'age' which is an integer, and 'grade' which is a text field. The task is to retrieve and print the records of a student based on their 'id'. The input required is a single integer representing the student ID. Use this input to query the 'students' table in the 'program_324_database.db' database and fetch the corresponding record.
[Example Input & Output]
- Input: 10\n ; Output: []
- Input: 2\n ; Output: [(2, 'Bob', 22, 'B')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
The database is named 'program_324_database.db' and contains a table called 'students'. This table has four columns: 'id' which is an integer and the primary key, 'name' which is a text field and cannot be null, 'age' which is an integer, and 'grade' which is a text field. The task is to retrieve and print the records of a student based on their 'id'. The input required is a single integer representing the student ID. Use this input to query the 'students' table in the 'program_324_database.db' database and fetch the corresponding record.
[Example Input & Output]
- Input: 10\n ; Output: []
- Input: 2\n ; Output: [(2, 'Bob', 22, 'B')]
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def main():
# Connect to the SQLite database
conn = sqlite3.connect('program_324_database.db')
cursor = conn.cursor()
# Prompt the user for a student ID
student_id = input("Enter student ID: ")
# Execute the query to select all records from the 'students' table where the ID matches the input
cursor.execute("SELECT * FROM students WHERE id = ?", (student_id,))
result = cursor.fetchall()
# Print the result if found, otherwise print an empty list
if result:
for row in result:
print(row)
else:
print([])
# Close the database connection
conn.close()
if __name__ == "__main__":
main()
|
program_361
|
[
{
"content": "[Problem]\nYou have a database named 'program_361_database.db' which contains a table called 'menu'. This table has columns named 'item_id', 'item_name', and 'price'. Your task is to write a code snippet that connects to this database and retrieves menu items based on user inputs. The inputs should include a customer name, a minimum price, a maximum price, and a desired item name that might contain special characters. The code should calculate a price range multiplier using the maximum and minimum prices. Then, it should construct a SQL query to select items from the 'menu' table where the price is between the given minimum and maximum prices, or the item name matches the desired item, or the price matches the calculated multiplier. Finally, the code should execute this query, fetch the results, and print each item's name and price. Remember to close the database connection after fetching the results.\n\n[Example Input & Output]\n- Input: Eve\\n1.00\\n2.50\\nCoffee\\n ; Output: Soda 1.99\\nCoffee 2.49\n- Input: Rachel\\n1.50\\n5.00\\nSmoothie\\n ; Output: Salad 4.99\\nSoda 1.99\\nFries 2.99\\nIce Cream 3.49\\nMilkshake 4.49\\nCoffee 2.49\n\n[Instruction]\nWrite a Python script to deal with the task.\nYou need to take user's inputs via `input()` and build sql queries based on the inputs.\nPrint your final results using `print()` function.\nWrite your code inside ```python\\n[YOUR PYTHON CODE]```.",
"role": "user"
}
] |
[Problem]
You have a database named 'program_361_database.db' which contains a table called 'menu'. This table has columns named 'item_id', 'item_name', and 'price'. Your task is to write a code snippet that connects to this database and retrieves menu items based on user inputs. The inputs should include a customer name, a minimum price, a maximum price, and a desired item name that might contain special characters. The code should calculate a price range multiplier using the maximum and minimum prices. Then, it should construct a SQL query to select items from the 'menu' table where the price is between the given minimum and maximum prices, or the item name matches the desired item, or the price matches the calculated multiplier. Finally, the code should execute this query, fetch the results, and print each item's name and price. Remember to close the database connection after fetching the results.
[Example Input & Output]
- Input: Eve\n1.00\n2.50\nCoffee\n ; Output: Soda 1.99\nCoffee 2.49
- Input: Rachel\n1.50\n5.00\nSmoothie\n ; Output: Salad 4.99\nSoda 1.99\nFries 2.99\nIce Cream 3.49\nMilkshake 4.49\nCoffee 2.49
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.
|
<|im_start|>system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>
<|im_start|>user
[Problem]
You have a database named 'program_361_database.db' which contains a table called 'menu'. This table has columns named 'item_id', 'item_name', and 'price'. Your task is to write a code snippet that connects to this database and retrieves menu items based on user inputs. The inputs should include a customer name, a minimum price, a maximum price, and a desired item name that might contain special characters. The code should calculate a price range multiplier using the maximum and minimum prices. Then, it should construct a SQL query to select items from the 'menu' table where the price is between the given minimum and maximum prices, or the item name matches the desired item, or the price matches the calculated multiplier. Finally, the code should execute this query, fetch the results, and print each item's name and price. Remember to close the database connection after fetching the results.
[Example Input & Output]
- Input: Eve\n1.00\n2.50\nCoffee\n ; Output: Soda 1.99\nCoffee 2.49
- Input: Rachel\n1.50\n5.00\nSmoothie\n ; Output: Salad 4.99\nSoda 1.99\nFries 2.99\nIce Cream 3.49\nMilkshake 4.49\nCoffee 2.49
[Instruction]
Write a Python script to deal with the task.
You need to take user's inputs via `input()` and build sql queries based on the inputs.
Print your final results using `print()` function.
Write your code inside ```python\n[YOUR PYTHON CODE]```.<|im_end|>
|
import sqlite3
def fetch_menu_items():
# Connect to the SQLite database
conn = sqlite3.connect('program_361_database.db')
cursor = conn.cursor()
# Prompt user for input
user_name = input("Enter your name: ")
min_price = float(input("Enter the minimum price: "))
max_price = float(input("Enter the maximum price: "))
item_name = input("Enter the desired item name: ")
# Construct and execute the SQL query
query = """
SELECT * FROM menu_items
WHERE price BETWEEN ? AND ?
AND item_name LIKE ?
AND user_name = ?
"""
cursor.execute(query, (min_price, max_price, f"%{item_name}%", user_name))
# Fetch and print the results
results = cursor.fetchall()
if results:
for row in results:
print(row)
else:
print("No matching menu items found.")
# Close the database connection
conn.close()
# Example usage
fetch_menu_items()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.