Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Secret Valentines You ve built a website where people can specify who their crushes are. A person can have a crush on zero or more

Secret Valentines
Youve built a website where people can specify who their crushes are. A person can have a crush on zero or more others, and can be crushed on by zero of more others.
There are two tables for holding this data: a table (named names) that matches names to id numbers and a table (named crushed) that matches ids from persons and the person(s) they have a crush on.
Example data:
CREATE TABLE names (name TEXT, id INTEGER);
INSERT INTO names VALUES
('Josh',1),
('Emily',2),
('Cam',3),
('Zizhen',4),
('Jane',5),
('Jie',6),
('Dennis',7),
('Jacob',8),
('Carrie',9),
('Tim',10)
;
CREATE TABLE crushed (crusher INTEGER, crushed_on INTEGER);
INSERT INTO crushed VALUES
(1,2),
(2,1),
(8,9),
(8,1),
(9,5),
(3,10)
;
Write a python function (named get_crushes) that takes a filename of a sqlite database. This function should returns a list of strings with each string being a crusher-crushed_on pairing. However, if someone has no crushes, be sure to have a string representing that (see below). Order by crusher (then by crushed on name).
Example return value for the above data:
['Cam has a crush on Tim',
'Carrie has a crush on Jane',
'Dennis has a crush on nobody',
'Emily has a crush on Josh',
'Jacob has a crush on Carrie',
'Jacob has a crush on Josh',
'Jane has a crush on nobody',
'Jie has a crush on nobody',
'Josh has a crush on Emily',
'Tim has a crush on nobody',
'Zizhen has a crush on nobody']

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions