Step-by-step explanation:
# Function to access the database using the created user in task #1
def access_database(user_id):
# Connect to the database using the provided user ID
# Your code to establish a connection and authenticate the user
# Once connected, you can run the queries and perform operations using the user ID
run_query_4(user_id)
run_query_5(user_id)
run_query_6(user_id)
run_query_7(user_id)
run_query_8(user_id)
# Close the database connection
# Your code to close the connection
# Function to insert a user into the database
def insert_user(user_id, username):
# Check if the user with the given user ID already exists in the database
# Your code to query the database and check if the user exists
# If the user exists, return an error or handle accordingly
# Your code to handle the existing user case
# If the user doesn't exist, insert the user into the database
# Your code to insert the user with the provided user ID and username
# Function to insert a favorite band for a user
def insert_favorite(user_id, band_name):
# Check if the band exists in the database
# Your code to query the database and check if the band exists
# If the band doesn't exist, return an error or handle accordingly
# Your code to handle the non-existent band case
# If the band exists, insert it as a favorite for the user
# Your code to insert the favorite band for the user with the provided user ID
# Function to delete a favorite band for a user
def delete_favorite(user_id, band_name):
# Check if the band exists in the user's favorite list
# Your code to query the database and check if the band exists in the user's favorites
# If the band doesn't exist in the user's favorites, return an error or handle accordingly
# Your code to handle the non-existent favorite band case
# If the band exists in the user's favorites, delete it
# Your code to delete the favorite band for the user with the provided user ID
# Example usage
if __name__ == '__main__':
# Insert users
insert_user(1, "John")
insert_user(2, "Alice")
insert_user(3, "Bob")
# Insert favorites for each user
insert_favorite(1, "Metallica")
insert_favorite(1, "Iron Maiden")
insert_favorite(1, "Led Zeppelin")
insert_favorite(2, "AC/DC")
insert_favorite(2, "Queen")
insert_favorite(2, "Pink Floyd")
insert_favorite(3, "Nirvana")
insert_favorite(3, "The Beatles")
insert_favorite(3, "Radiohead")
# Delete a favorite band for a user
delete_favorite(1, "Iron Maiden")
# Access the database with user ID 1
access_database(1)