{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**a)** Take a few minutes to browse the modules in the [Python module index](https://docs.python.org/3/py-modindex.html)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**b)** Import the module `datetime`, a module that provides functionality for working with dates. We will now use it to calculate your age in days, hours and seconds repsectively.\n",
"\n",
"Write a function that accepts a birth date of a person:\n",
"\n",
"`> calculate_age(1999, 1, 2, hour=12, minute=2, second=33)`\n",
"```\n",
"You are 7263 days old\n",
"You are 174313 hours old\n",
"You are 627527127 seconds old\n",
"```\n",
"\n",
"\n",
"Year, month and date is required, the other values are optional. The default values of hour, minute and second should be 0.\n",
"\n",
"The function should print the following:\n",
"\n",
"- How many days is the person?\n",
"- How many hours is the person?\n",
"- How many seconds is the person?\n",
"\n",
"The `datetime` module will provide you with the number of days and seconds. You will need to calculate the number of hours on your own.\n",
"\n",
"**Hints:**\n",
"- Use the [`datetime Object`](https://docs.python.org/3/library/datetime.html#datetime-objects) to solve the exercise.\n",
"\n",
"- Find out how to make a `datetime` object representing the current time.\n",
"\n",
"- Find out how to make a `datetime` object representing a given date and time (the birth date). \n",
"\n",
"- Look at the supported operations for this type to find how you can get the difference between two objects of type `datetime`.\n",
"\n",
"- You will get difference represented as an object (a [`timedelta`](https://docs.python.org/3/library/datetime.html#timedelta-objects)).\n",
"\n",
"- Use `.days` and `.total_seconds()` to get the number of days and seconds."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**c)** Test your functions by giving it different input and make sure that they give the expected output."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bonus exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**d)** Go back to the previous IMDB exercise, where you defined the `pick_movie()` function.\n",
"\n",
"Use the module `random` to make the movie picker less predictable: instead of always returning the first matching movie from the file, return a randomly picked movie (which still matches the user's criteria)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"-----\n",
"
\n",
"
\n",
"
\n",
"