|
554 | 554 | "\n", |
555 | 555 | "from attrs import define\n", |
556 | 556 | "\n", |
557 | | - "def solution_child_eye_color(mother_eye_color: str, father_eye_color: str) -> str:\n", |
| 557 | + "def solution_child_eye_color(mother_eye_color: str, father_eye_color: str) -> list:\n", |
558 | 558 | " \"\"\"\n", |
559 | 559 | " Given the eye colors of the mother and father, defines the eye color of the child.\n", |
560 | 560 | " The possible eye colors are: brown or blue, with brown being the dominant one.\n", |
|
1475 | 1475 | "\n", |
1476 | 1476 | "<div class=\"alert alert-block alert-warning\">\n", |
1477 | 1477 | " <h4><b>Question</b></h4>\n", |
1478 | | - " Complete the solution function such that it creates the instances of the two computers mentioned in the list below.\n", |
1479 | | - " <strong>Pay attention to the type!</strong>\n", |
| 1478 | + " Complete the solution function such that it creates the instances of the two computers mentioned below.\n", |
| 1479 | + " They will be automatically passed as arguments to the solution function.\n", |
1480 | 1480 | " </br>\n", |
1481 | | - " This function should return a list that collects the <strong>string representations</strong> of the two computers.\n", |
| 1481 | + " This function should return a list that collects the two instances you created.\n", |
1482 | 1482 | "</div>" |
1483 | 1483 | ] |
1484 | 1484 | }, |
|
1491 | 1491 | "source": [ |
1492 | 1492 | "%%ipytest\n", |
1493 | 1493 | "\n", |
1494 | | - "computers = [\n", |
1495 | | - " {\n", |
1496 | | - " \"type\": \"PC\",\n", |
1497 | | - " \"name\": \"pc_1\",\n", |
1498 | | - " \"price\": 1500,\n", |
1499 | | - " \"quantity\": 1,\n", |
1500 | | - " \"expansion_slots\": 2\n", |
1501 | | - " },\n", |
1502 | | - " {\n", |
1503 | | - " \"type\": \"Laptop\",\n", |
1504 | | - " \"name\": \"laptop_1\",\n", |
1505 | | - " \"price\": 1200,\n", |
1506 | | - " \"quantity\": 4,\n", |
1507 | | - " \"battery_life\": 6\n", |
1508 | | - " }\n", |
1509 | | - "]\n", |
| 1494 | + "pc = {\n", |
| 1495 | + " \"name\": \"pc_1\",\n", |
| 1496 | + " \"price\": 1500,\n", |
| 1497 | + " \"quantity\": 1,\n", |
| 1498 | + " \"expansion_slots\": 2\n", |
| 1499 | + "}\n", |
| 1500 | + "\n", |
| 1501 | + "laptop = {\n", |
| 1502 | + " \"name\": \"laptop_1\",\n", |
| 1503 | + " \"price\": 1200,\n", |
| 1504 | + " \"quantity\": 4,\n", |
| 1505 | + " \"battery_life\": 6\n", |
| 1506 | + "}\n", |
| 1507 | + "\n", |
| 1508 | + "def solution_store_inventory(pc: dict, laptop: dict) -> list:\n", |
| 1509 | + " \"\"\"\n", |
| 1510 | + " Creates instances of `PC` and `Laptop` classes based on the provided input dictionaries.\n", |
| 1511 | + " The `Computer` class serves as the base class with attributes `name`, `price`, and `quantity`.\n", |
| 1512 | + " The `PC` and `Laptop` classes inherit from `Computer` and extend it with additional attributes:\n", |
| 1513 | + " - `PC` includes `expansion_slots`.\n", |
| 1514 | + " - `Laptop` includes `battery_life`.\n", |
1510 | 1515 | "\n", |
| 1516 | + " Each class implements the `__init__` and `__str__` methods:\n", |
| 1517 | + " - `Computer.__str__`: Returns a string representation of the `Computer` instance.\n", |
| 1518 | + " - `PC.__str__`: Appends to the `Computer` string.\n", |
| 1519 | + " - `Laptop.__str__`: Appends to the `Computer` string.\n", |
1511 | 1520 | "\n", |
1512 | | - "def solution_store_inventory(computers: list[dict]) -> list[str]:\n", |
1513 | | - " # Write your solution here\n", |
1514 | | - " pass" |
| 1521 | + " Args:\n", |
| 1522 | + " pc: A dictionary containing the attributes for the `PC` instance.\n", |
| 1523 | + " laptop: A dictionary containing the attributes for the `Laptop` instance.\n", |
| 1524 | + " Returns:\n", |
| 1525 | + " A list containing the created the `PC` and `Laptop` instances.\n", |
| 1526 | + " \"\"\"\n", |
| 1527 | + "\n", |
| 1528 | + " return" |
1515 | 1529 | ] |
1516 | 1530 | }, |
1517 | 1531 | { |
|
1529 | 1543 | "- **User** with attributes: username, playlists.\n", |
1530 | 1544 | "\n", |
1531 | 1545 | "Based on these, create the respective classes:\n", |
1532 | | - "- `Song`: should contain attributes `title` (string), `artist` (string) and `album_title` (string)\n", |
1533 | | - "- `Playlist`: should contain attributes `name` (string) and `songs` (a list of `Song` instances). It should also include a method for adding song a song to the playlist.\n", |
1534 | | - "- `User`: should contain attributes `name` (string) and `playlists` (a dict where key is the name of the playlist and value is a `Playlist` instance). It should also include a method for creating a playlist and a method for adding a specific song to a specific playlist.\n", |
| 1546 | + "- `Song`: should contain attributes `title` (string), `artist` (string) and `album_title` (string).\n", |
| 1547 | + "- `Playlist`: should contain attributes `name` (string) and `songs` (a list of `Song` instances). It should also include a method for adding a song to the playlist.\n", |
| 1548 | + "- `User`: should contain attributes `username` (string) and `playlists` (a dict where key is the name of the playlist and value is a `Playlist` instance). It should also include a method for creating a playlist and a method for adding a specific song to a specific playlist.\n", |
1535 | 1549 | "\n", |
1536 | 1550 | "<div class=\"alert alert-block alert-warning\">\n", |
1537 | 1551 | " <h4><b>Question</b></h4>\n", |
1538 | 1552 | " Using <strong>composition</strong> in Python, create a music streaming service system that includes the classes mentioned above.\n", |
1539 | 1553 | " Create <strong>one user that has one playlist</strong>, containing the songs provided in the list below.\n", |
1540 | | - " Your solution function should <strong>return the <code>User</code></strong> instance.\n", |
| 1554 | + " They will be automatically passed as arguments to the solution function.\n", |
| 1555 | + " The user's username and the name of the playlist are also provided.\n", |
| 1556 | + " </br>\n", |
| 1557 | + " Your solution function should return the <code>User</code> instance.\n", |
1541 | 1558 | "</div>" |
1542 | 1559 | ] |
1543 | 1560 | }, |
|
1568 | 1585 | " },\n", |
1569 | 1586 | "]\n", |
1570 | 1587 | "\n", |
1571 | | - "def solution_music_streaming_service(song_info: list[dict]):\n", |
1572 | | - " # Write your solution here\n", |
1573 | | - " pass" |
| 1588 | + "def solution_music_streaming_service(song_info: list[dict], username: str, playlist_name: str):\n", |
| 1589 | + " \"\"\"\n", |
| 1590 | + " Creates a music streaming service system using composition, including classes for `Song`, `Playlist`, and `User`:\n", |
| 1591 | + " - `Song` represents a song with:\n", |
| 1592 | + " - title\n", |
| 1593 | + " - artist\n", |
| 1594 | + " - album_title\n", |
| 1595 | + " - `Playlist` represents a playlist with:\n", |
| 1596 | + " - name\n", |
| 1597 | + " - songs\n", |
| 1598 | + " - Includes a method to add a song to the playlist.\n", |
| 1599 | + " - `User` represents a user with:\n", |
| 1600 | + " - username\n", |
| 1601 | + " - playlists\n", |
| 1602 | + " - Includes methods to create a playlist and add a song to a specific playlist.\n", |
| 1603 | + "\n", |
| 1604 | + " Args:\n", |
| 1605 | + " song_info: A list of dictionaries, where each dictionary contains the details of a song.\n", |
| 1606 | + " Returns:\n", |
| 1607 | + " An instance of the `User` class with one playlist containing the provided songs.\n", |
| 1608 | + " \"\"\"\n", |
| 1609 | + "\n", |
| 1610 | + " return" |
1574 | 1611 | ] |
1575 | 1612 | }, |
1576 | 1613 | { |
|
1796 | 1833 | "%%ipytest\n", |
1797 | 1834 | "\n", |
1798 | 1835 | "def solution_n_body(universe_start: str) -> int:\n", |
1799 | | - " # Write your solution here\n", |
1800 | | - " pass" |
| 1836 | + " \"\"\"\n", |
| 1837 | + " Simulates the motion of moons in a 3-dimensional space over a specified number of time steps\n", |
| 1838 | + " and calculates the average total energy of the system.\n", |
| 1839 | + "\n", |
| 1840 | + " The simulation involves:\n", |
| 1841 | + " 1. Updating the velocity of each moon based on the gravitational interaction with other moons.\n", |
| 1842 | + " 2. Updating the position of each moon by applying its velocity.\n", |
| 1843 | + " 3. Calculating the total energy of the system after the simulation.\n", |
| 1844 | + "\n", |
| 1845 | + " Total energy for a single moon is calculated as:\n", |
| 1846 | + " - Potential energy: The sum of the absolute values of its positional coordinates.\n", |
| 1847 | + " - Kinetic energy: The sum of the absolute values of its velocity components.\n", |
| 1848 | + " - Total energy: Potential energy multiplied by kinetic energy.\n", |
| 1849 | + "\n", |
| 1850 | + " Args:\n", |
| 1851 | + " universe_start (str): A string representing the initial positions of the moons in the format:\n", |
| 1852 | + " \"MoonName: x=<value>, y=<value>, z=<value>\"\n", |
| 1853 | + "\n", |
| 1854 | + " Returns:\n", |
| 1855 | + " int: The average total energy of the system after simulating the universe for 1000 time steps.\n", |
| 1856 | + " \"\"\"\n", |
| 1857 | + "\n", |
| 1858 | + " return" |
1801 | 1859 | ] |
1802 | 1860 | } |
1803 | 1861 | ], |
|
0 commit comments