Dataset Viewer
Auto-converted to Parquet
problem_id
stringlengths
9
11
conversation
listlengths
1
1
prompt_raw
stringlengths
884
2.13k
prompt_text
stringlengths
1.01k
2.26k
response
stringlengths
0
1.8k
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 os import sqlite3 db_path = os.getenv('DB_PATH') if db_path is None: print("Environment variable DB_PATH is not set.") else: conn = sqlite3.connect(db_path) cursor = conn.cursor() item_type = input("Enter item type to search: ") query = "SELECT * FROM inventory WHERE item_type = ?" cursor.execute(query, (item_type,)) for row in cursor.fetchall(): print(row) cursor.close() 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 from os import environ def main(): min_price = float(input("Enter minimum price: ")) max_price = float(input("Enter maximum price: ")) genre = input("Enter genre: ") conn = sqlite3.connect('program_60_database.db') cursor = conn.cursor() adjusted_min_price = min_price * 0.95 adjusted_max_price = max_price * 1.05 query = "SELECT title, author, price, genre FROM books WHERE price BETWEEN ? AND ? AND genre = ?" cursor.execute(query, (adjusted_min_price, adjusted_max_price, genre)) results = cursor.fetchall() for row in results: print(f"Title: {row[0]}, Author: {row[1]}, Price: {row[2]}, Genre: {row[3]}") 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 # Connect to the database conn = sqlite3.connect('program_225_database.db') cursor = conn.cursor() # Get user inputs search_term = input().strip() filter_type = input().strip().lower() # Build the SQL query based on user inputs if filter_type == 'username': query = f"SELECT * FROM users WHERE username LIKE ?" elif filter_type == 'email': query = f"SELECT * FROM users WHERE email LIKE ?" else: print("Invalid filter type. Please choose 'username' or 'email'.") conn.close() exit() # Execute the query cursor.execute(query, ('%' + search_term + '%',)) # Fetch and print the results results = cursor.fetchall() for row in results: print(row) # Close the connection conn.close()
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 main(): conn = None try: conn = sqlite3.connect('program_277_database.db') cursor = conn.cursor() event_name = input("Enter event name: ") start_date = input("Enter start date (YYYY-MM-DD): ") end_date = input("Enter end date (YYYY-MM-DD): ") location = input("Enter location: ") query = "SELECT * FROM tickets WHERE event_name=? AND start_date=? AND end_date=? AND location=?" cursor.execute(query, (event_name, start_date, end_date, location)) results = cursor.fetchall() if results: for row in results: print(row) else: print("No matching records found.") except sqlite3.Error as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def get_input(): min_income = float(input("Enter minimum income: ")) age = int(input("Enter age: ")) employment_status = input("Enter employment status: ") adj_factor = float(input("Enter adjustment factor: ")) return min_income, age, employment_status, adj_factor def calculate_adjusted_min_income(min_income, adj_factor): return min_income * adj_factor def main(): min_income, age, employment_status, adj_factor = get_input() conn = sqlite3.connect('program_356_database.db') cursor = conn.cursor() adjusted_min_income = calculate_adjusted_min_income(min_income, adj_factor) query = "SELECT * FROM census_data WHERE min_income > ? AND age > ? AND employment_status = ?" cursor.execute(query, (adjusted_min_income, age, employment_status)) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close() if __name__ == "__main__": main()
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 import os def main(): db_path = 'program_149_database.db' # Connect to the SQLite database conn = sqlite3.connect(db_path) cursor = conn.cursor() # Prompt user for item ID or description item_id = input("Enter item ID: ") description = input("Enter item description: ") # Execute query to select items based on ID or description query = "SELECT * FROM items WHERE item_id=? OR description=?" cursor.execute(query, (item_id, description)) # Fetch and print results results = cursor.fetchall() for row in results: print(row) # Close the database connection conn.close() if __name__ == "__main__": main()
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 os import sqlite3 # Retrieve database path from environment variable, default to 'program_407_database.db' db_path = os.getenv('DB_PATH', 'program_407_database.db') # Connect to the SQLite database conn = sqlite3.connect(db_path) # Create a cursor object using the cursor() method cursor = conn.cursor() # Prompt user for input min_price = float(input("Enter minimum price: ")) max_price = float(input("Enter maximum price: ")) event_date = input("Enter event date: ") event_name_substring = input("Enter event name substring: ") # Construct SQL query query = """ SELECT * FROM tickets WHERE price BETWEEN ? AND ? AND date = ? AND event_name LIKE ? """ # Execute the SQL query cursor.execute(query, (min_price, max_price, event_date, f'%{event_name_substring}%')) # Fetch all the rows in a list of lists. results = cursor.fetchall() # Print out the results for row in results: print(row) # Close the cursor and connection cursor.close() conn.close()
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|>
Ensure it follows the guidelines provided. import sqlite3 import os def get_env_variable(var_name): return os.getenv(var_name) DB_NAME = get_env_variable('DATABASE_NAME') SECRET_KEY = get_env_variable('SECRET_KEY') conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() 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 a keyword: ") query = """ SELECT * FROM posts WHERE author = ? AND publish_date BETWEEN ? AND ? AND (title LIKE '%' || ? || '%' OR content LIKE '%' || ? || '%') """ cursor.execute(query, (author, start_date, end_date, keyword, keyword)) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close()
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 os import environ def fetch_events(): location = input("Enter location: ") event_date = input("Enter event date (YYYY-MM-DD): ") ticket_amount = int(input("Enter ticket amount: ")) conn = sqlite3.connect('program_185_database.db') cur = conn.cursor() # Use parameterized queries to avoid SQL injection cur.execute("SELECT * FROM events WHERE location=? AND event_date=? AND ticket_amount=?", (location, event_date, ticket_amount)) rows = cur.fetchall() for row in rows: print(row) cur.close() conn.close() if __name__ == "__main__": fetch_events()
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|>
Ensure it adheres to the guidelines provided. from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy from datetime import date app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///reservations.db' db = SQLAlchemy(app) class Reservations(db.Model): id = db.Column(db.Integer, primary_key=True) room_type = db.Column(db.String(80), nullable=False) check_in_date = db.Column(db.Date, nullable=False) check_out_date = db.Column(db.Date, nullable=False) max_price = db.Column(db.Float, nullable=False) @app.route('/search_reservations', methods=['GET']) def search_reservations(): try: room_type = request.args.get('room_type') check_in_date = request.args.get('check_in_date') check_out_date = request.args.get('check_out_date') max_price = request.args.get('max_price') query = Reservations.query.filter_by(room_type=room_type) if check_in_date: query = query.filter(Reservations.check_in_date == date.fromisoformat(check_in_date)) if check_out_date: query = query.filter(Reservations.check_out_date == date.fromisoformat(check_out_date)) if max_price: query = query.filter(Reservations.max_price <= float(max_price)) results = [] for res in query.all(): results.append({ 'id': res.id, 'room_type': res.room_type, 'check_in_date': res.check_in_date.isoformat(), 'check_out_date': res.check_out_date.isoformat(), 'max_price': res.max_price }) return jsonify(results) except Exception as e: return jsonify({'error': str(e)}), 500 if __name__ == '__main__': app.run(debug=True)
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 from datetime import datetime def main(): # Connect to the SQLite database conn = sqlite3.connect('program_78_database.db') cursor = conn.cursor() # Get user inputs 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 effective_price_threshold = price_threshold * (1 - bulk_discount_percentage / 100) # Construct SQL query query = """ SELECT * FROM orders WHERE order_date BETWEEN ? AND ? AND status = ? AND total_price >= ? """ # Execute query cursor.execute(query, (start_date, end_date, order_status, effective_price_threshold)) results = cursor.fetchall() # Print results for row in results: print(row) # Close the database connection conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def fetch_inventory(): conn = None try: db_path = os.getenv('DB_PATH') if not db_path: raise ValueError("Database path not set") conn = sqlite3.connect(db_path) cursor = conn.cursor() category = input("Enter item category: ") query = "SELECT * FROM inventory WHERE category=?" cursor.execute(query, (category,)) records = cursor.fetchall() for record in records: print(record) except Exception as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": fetch_inventory()
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 os import sqlite3 def main(): min_age = input("Enter minimum age: ") max_age = input("Enter maximum age: ") target_city = input("Enter target city: ") include_younger_than_min = input("Include customers younger than the minimum age? (yes/no): ").lower() == "yes" conn = sqlite3.connect('program_24_database.db') cursor = conn.cursor() query_parts = ['SELECT * FROM customers'] conditions = [] if min_age: conditions.append(f"age >= {min_age}") if max_age: conditions.append(f"age <= {max_age}") if target_city: conditions.append(f"city = '{target_city}'") if include_younger_than_min: conditions.append("age < :min_age") if conditions: query_parts.append('WHERE') query_parts.extend(conditions) query = ' '.join(query_parts) print(f"Executing query: {query}") cursor.execute(query, {'min_age': min_age}) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def main(): min_price = input("Enter minimum price: ") max_price = input("Enter maximum price: ") category = input("Enter category: ") conn = sqlite3.connect(os.getenv('DATABASE_URL')) cursor = conn.cursor() query = "SELECT * FROM orders WHERE price BETWEEN ? AND ? AND category = ?" cursor.execute(query, (min_price, max_price, category)) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def main(): db_path = os.getenv('DB_PATH') if not db_path: print("Database path not set.") return conn = sqlite3.connect(db_path) cursor = conn.cursor() account_id = input("Enter Account ID: ") min_balance = float(input("Enter Minimum Balance: ")) query = """ SELECT * FROM accounts WHERE id = ? AND balance >= ? """ cursor.execute(query, (account_id, min_balance)) results = cursor.fetchall() for row in results: print(row) cursor.close() 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 from os import environ def get_user_input(): category = input("Enter category: ") max_price = float(input("Enter maximum price: ")) product_id = int(input("Enter product ID: ")) search_term = input("Enter search term (optional): ") sort_by = input("Enter column to sort by: ") sort_direction = input("Enter sorting direction (ASC/DESC): ").upper() return category, max_price, product_id, search_term, sort_by, sort_direction def construct_query(category, max_price, product_id, search_term, sort_by, sort_direction): base_query = "SELECT * FROM products WHERE category=? AND price<=? AND id=?" params = [category, max_price, product_id] if search_term: base_query += " AND name LIKE ?" params.append(f"%{search_term}%") base_query += f" ORDER BY {sort_by} {sort_direction}" return base_query, params def main(): category, max_price, product_id, search_term, sort_by, sort_direction = get_user_input() query, params = construct_query(category, max_price, product_id, search_term, sort_by, sort_direction) conn = sqlite3.connect('program_235_database.db') cursor = conn.cursor() cursor.execute(query, params) rows = cursor.fetchall() for row in rows: print(row) cursor.close() conn.close() if __name__ == "__main__": main()
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 os import environ def fetch_billing_data(): conn = sqlite3.connect('program_217_database.db') cur = conn.cursor() start_date = input("Enter start date (YYYY-MM-DD): ") end_date = input("Enter end date (YYYY-MM-DD): ") min_amount_due = float(input("Enter minimum amount due: ")) payment_status = input("Enter payment status: ") query = """ SELECT * FROM billing WHERE billing_date BETWEEN ? AND ? AND amount_due >= ? AND status = ? """ cur.execute(query, (start_date, end_date, min_amount_due, payment_status)) results = cur.fetchall() for row in results: print(row) cur.close() conn.close() fetch_billing_data()
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 os import sqlite3 def main(): conn = None try: db_path = os.path.join(os.getcwd(), 'program_174_database.db') conn = sqlite3.connect(db_path) cursor = conn.cursor() researcher_name = input("Enter researcher's name: ") query = "SELECT * FROM studies WHERE researcher_name = ?" cursor.execute(query, (researcher_name,)) results = cursor.fetchall() for row in results: print(row) except sqlite3.Error as e: print(f"Error: {e}") finally: if conn: conn.close() 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 os 2 import sqlite3 3 4 def main(): 5 start_date = input("Enter start date (YYYY-MM-DD): ") 6 end_date = input("Enter end date (YYYY-MM-DD): ") 7 min_audience_size = int(input("Enter minimum audience size: ")) 8 desired_conversion_ratio = float(input("Enter desired conversion ratio: ")) 9 10 conn = sqlite3.connect('program_315_database.db') 11 cursor = conn.cursor() 12 13 query = f"SELECT * FROM campaigns WHERE start_date >= ? AND end_date <= ? AND audience_size >= ? AND conversion_rate >= ?" 14 cursor.execute(query, (start_date, end_date, min_audience_size, desired_conversion_ratio)) 15 16 results = cursor.fetchall() 17 for row in results: 18 print(row) 19 20 cursor.close() 21 conn.close() 22 23 if __name__ == "__main__": 24 main()
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 adjust_weight(weight): return weight * 1.2 def adjust_rating(rating): return rating + 0.5 db_path = os.getenv('DB_PATH') conn = sqlite3.connect(db_path) cursor = conn.cursor() min_weight = float(input("Enter minimum weight: ")) max_weight = float(input("Enter maximum weight: ")) min_rating = float(input("Enter minimum rating: ")) category = input("Enter category: ") adjusted_min_weight = adjust_weight(min_weight) adjusted_max_weight = adjust_weight(max_weight) adjusted_min_rating = adjust_rating(min_rating) query = "SELECT * FROM products WHERE weight BETWEEN ? AND ? AND rating >= ? AND category = ?" cursor.execute(query, (adjusted_min_weight, adjusted_max_weight, adjusted_min_rating, category)) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close()
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 from os import environ def connect_to_db(): return sqlite3.connect(environ['DATABASE_URL']) def main(): conn = connect_to_db() cursor = conn.cursor() title = input("Enter book title: ") author = input("Enter author name: ") query = "SELECT * FROM books WHERE title=? AND author=?" cursor.execute(query, (title, author)) results = cursor.fetchall() for row in results: print(row) cursor.close() 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 os 2 import sqlite3 3 4 conn = None 5 try: 6 db_path = os.path.join(os.getcwd(), 'program_348_database.db') 7 conn = sqlite3.connect(db_path) 8 cursor = conn.cursor() 9 10 customer_name = input("Enter customer name: ") 11 min_price = float(input("Enter minimum price: ")) 12 max_price = float(input("Enter maximum price: ")) 13 14 query = f"SELECT * FROM orders WHERE customer_name = ? AND price BETWEEN ? AND ?" 15 cursor.execute(query, (customer_name, min_price, max_price)) 16 17 results = cursor.fetchall() 18 for row in results: 19 print(row) 20 21 except Exception as e: 22 print(f"Error: {e}") 23 finally: 24 if conn: 25 conn.close()
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|>
from os import environ import sqlite3 DATABASE_URL = environ.get('DATABASE_URL', 'sqlite:///program_231_database.db') def main(): conn = sqlite3.connect(DATABASE_URL) cursor = conn.cursor() account_number = input("Enter account number: ") min_amount = float(input("Enter minimum transaction amount: ")) query = """ SELECT * FROM transactions WHERE account_number = ? AND amount >= ? """ cursor.execute(query, (account_number, min_amount)) results = cursor.fetchall() for row in results: print(row) cursor.close() 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 search_inventory(item_name, supplier, min_quantity): conn = sqlite3.connect('program_245_database.db') cursor = conn.cursor() query = "SELECT * FROM inventory WHERE item_name=? AND supplier=? AND quantity>=?" cursor.execute(query, (item_name, supplier, min_quantity)) results = cursor.fetchall() for row in results: print(row) conn.close() def display_inventory(): conn = sqlite3.connect('program_245_database.db') cursor = conn.cursor() query = "SELECT * FROM inventory" cursor.execute(query) results = cursor.fetchall() for row in results: print(row) conn.close() if __name__ == "__main__": item_name = input("Enter item name: ") supplier = input("Enter supplier name: ") min_quantity = int(input("Enter minimum quantity: ")) search_inventory(item_name, supplier, min_quantity) display_inventory()
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): conn = None try: # Connect to the SQLite database conn = sqlite3.connect('program_445_database.db') # Create a cursor object using the cursor() method cursor = conn.cursor() # Prepare SQL query to INSERT a record into the database. sql = "SELECT * FROM employees WHERE id = ?" cursor.execute(sql, (employee_id,)) # Fetch all rows from the last executed statement results = cursor.fetchall() if len(results) == 0: print("No employee found with the given ID.") else: for row in results: print(row) except sqlite3.Error as e: print(f"Error: {e}") finally: # Close the database connection if conn: conn.close() if __name__ == "__main__": employee_id = input("Enter employee ID: ") 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 os import sqlite3 def get_connection(): db_path = os.getenv('DB_PATH') if not db_path: raise ValueError("DB_PATH environment variable is not set") conn = sqlite3.connect(db_path) return conn def fetch_patient_records(name): conn = get_connection() cursor = conn.cursor() query = "SELECT * FROM patients WHERE name = ?" cursor.execute(query, (name,)) records = cursor.fetchall() for record in records: print(record) cursor.close() conn.close() if __name__ == "__main__": patient_name = input("Enter patient's name: ") fetch_patient_records(patient_name)
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 # Get environment variable for secret key SECRET_KEY = os.getenv('SECRET_KEY') def connect_to_db(): conn = sqlite3.connect('program_393_database.db') return conn def fetch_student_record(student_id): conn = connect_to_db() cursor = conn.cursor() query = "SELECT * FROM students WHERE id = ?" cursor.execute(query, (student_id,)) result = cursor.fetchone() cursor.close() conn.close() return result def main(): student_id = input("Enter Student ID: ") if not student_id: print("Student ID cannot be empty.") return student_record = fetch_student_record(student_id) if student_record: print(f"Student Record: {student_record}") else: print("No student record found.") if __name__ == "__main__": main()
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 os import sqlite3 def main(): password = os.getenv('DB_PASSWORD') if not password: raise ValueError("DB_PASSWORD environment variable is not set") conn = sqlite3.connect('program_382_database.db', password=password) cursor = conn.cursor() min_age = int(input("Enter minimum age: ")) country = input("Enter country: ") keyword = input("Enter keyword in bio: ") query = """ SELECT * FROM users WHERE age >= ? AND country = ? AND bio LIKE ? """ cursor.execute(query, (min_age, country, f'%{keyword}%')) results = cursor.fetchall() for row in results: print(row) cursor.close() 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 os import sqlite3 def get_customer_orders(): try: # Connect to the SQLite database using an environment variable for the path db_path = os.getenv('DATABASE_PATH') if not db_path: raise ValueError("Database path not set in environment variables") conn = sqlite3.connect(db_path) cursor = conn.cursor() # Prompt user for customer name customer_name = input("Enter customer name: ") # Execute query to select all orders for the provided customer name cursor.execute("SELECT * FROM orders WHERE customer_name = ?", (customer_name,)) # Fetch and print the results results = cursor.fetchall() for row in results: print(row) except Exception as e: print(f"An error occurred: {e}") finally: # Close the database connection if conn: conn.close() if __name__ == "__main__": get_customer_orders()
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 os import sqlite3 SECRET_KEY = os.getenv('SECRET_KEY') def validate_input(input): if input.strip() == "": raise ValueError("Input cannot be empty") def main(): try: conn = sqlite3.connect('program_372_database.db') cursor = conn.cursor() print("Search Criteria: 1 - Name, 2 - Age") choice = input("Enter your choice (1/2): ") validate_input(choice) if choice == "1": name = input("Enter name: ") validate_input(name) cursor.execute("SELECT * FROM users WHERE name=?", (name,)) elif choice == "2": age = input("Enter age: ") validate_input(age) cursor.execute("SELECT * FROM users WHERE age=?", (age,)) else: raise ValueError("Invalid choice") results = cursor.fetchall() if len(results) > 0: for row in results: print(row) else: print("No results found.") except Exception as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": main()
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(): conn = sqlite3.connect('program_301_database.db') cursor = conn.cursor() campaign_name = input("Enter campaign name: ") query = "SELECT * FROM marketing_campaigns WHERE campaign_name = ?" cursor.execute(query, (campaign_name,)) results = cursor.fetchall() if len(results) == 0: print("No matching campaign found.") else: for row in results: print(row) cursor.close() 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 from os import environ def fetch_orders(): conn = None try: # Connect to the SQLite database using an environment variable for the password password = environ.get('DB_PASSWORD') conn = sqlite3.connect(f"sqlite:///program_170_database.db", password=password) cursor = conn.cursor() # Prompt the user to enter a customer name customer_name = input("Enter customer name: ") # Fetch all orders for the specified customer query = "SELECT * FROM sales WHERE customer_name = ?" cursor.execute(query, (customer_name,)) # Print the results rows = cursor.fetchall() for row in rows: print(row) except Exception as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": fetch_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 from os import environ def main(): min_balance = float(input("Enter minimum account balance: ")) max_balance = float(input("Enter maximum account balance: ")) bonus_percentage = float(input("Enter bonus percentage: ")) membership_level = input("Enter membership level: ") effective_min_balance = min_balance * (1 + bonus_percentage / 100) effective_max_balance = max_balance * (1 + bonus_percentage / 100) conn = sqlite3.connect('program_370_database.db') cursor = conn.cursor() query = """ SELECT * FROM customer_info WHERE (balance BETWEEN ? AND ?) OR membership_level = ? """ cursor.execute(query, (effective_min_balance, effective_max_balance, membership_level)) results = cursor.fetchall() for row in results: print(row) 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|>
from os import environ import sqlite3 def main(): conn = sqlite3.connect('program_345_database.db') cursor = conn.cursor() year = input("Enter the publication year: ") category = input("Enter the research category: ") query = "SELECT * FROM papers WHERE publication_year = ? AND research_category = ?" cursor.execute(query, (year, category)) results = cursor.fetchall() for row in results: print(row) cursor.close() 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 os import sqlite3 def main(): conn = None try: db_path = os.getenv('DB_PATH') if not db_path: raise ValueError("Database path not set in environment variables") conn = sqlite3.connect(db_path) cursor = conn.cursor() item_name = input("Enter item name to search: ") query = "SELECT * FROM inventory WHERE item_name LIKE ?" cursor.execute(query, ('%' + item_name + '%',)) results = cursor.fetchall() for row in results: print(row) except Exception as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": main()
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 import os def main(): min_temp = float(input("Enter minimum temperature: ")) max_temp = float(input("Enter maximum temperature: ")) location = input("Enter location: ") device_status = input("Enter device status: ") conn = sqlite3.connect('program_384_database.db') cursor = conn.cursor() adj_min_temp = min_temp + 0.5 adj_max_temp = max_temp + 0.5 query = """ SELECT * FROM devices WHERE ((? <= temperature AND temperature <= ?) OR (location = ? AND status = ?)) """ cursor.execute(query, (adj_min_temp, adj_max_temp, location, device_status)) results = cursor.fetchall() for row in results: print(row) conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def main(): db_path = os.getenv('DB_PATH') if not db_path: print("Database path not set in environment variables.") return conn = None try: conn = sqlite3.connect(db_path) cursor = conn.cursor() product_name = input("Enter product name to search: ") query = "SELECT * FROM products WHERE name LIKE ?" cursor.execute(query, ('%' + product_name + '%',)) results = cursor.fetchall() if results: for row in results: print(row) else: print("No products found.") except sqlite3.Error as e: print(f"Error connecting to database: {e}") finally: if conn: conn.close() if __name__ == "__main__": main()
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 os import sqlite3 def main(): min_friends = int(input("Enter minimum number of friends: ")) max_friends = int(input("Enter maximum number of friends: ")) age_preference = int(input("Enter age preference: ")) keyword = input("Enter keyword: ") conn = sqlite3.connect('program_215_database.db') cursor = conn.cursor() query = """ SELECT * FROM users WHERE num_friends BETWEEN ? AND ? AND age BETWEEN ? AND 99 AND name LIKE ? """ cursor.execute(query, (min_friends, max_friends, age_preference, f'%{keyword}%')) results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close() if __name__ == "__main__": main()
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 def main(): conn = None try: conn = sqlite3.connect('program_208_database.db') cursor = conn.cursor() title = input("Enter the title of the listing: ") query = "SELECT * FROM listings WHERE title = ?" cursor.execute(query, (title,)) results = cursor.fetchall() for row in results: print(row) except sqlite3.Error as e: print(f"An error occurred: {e}") finally: if conn: conn.close() if __name__ == "__main__": main()
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
5