Add exercises for std lib notebooks
This commit is contained in:
117
notebooks/beginner/exercises/std_lib1_exercise.ipynb
Normal file
117
notebooks/beginner/exercises/std_lib1_exercise.ipynb
Normal file
@@ -0,0 +1,117 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# pytz will be needed in the exercise\n",
|
||||
"import sys\n",
|
||||
"!{sys.executable} -m pip install pytz"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 1. Playing with datetimes\n",
|
||||
"You're given a naive datetime, see `NAIVE_DT` variable below. Although this variable is naive, you happen to know that the time specified by `NAIVE_DT` is in UTC.\n",
|
||||
"\n",
|
||||
"Based on this information, your task is to create new datetime variables by converting `NAIVE_DT` to UTC and then to time in Sydney and Los Angeles. Use the following variable names: `utc_dt`, `sydney_dt`, and `la_dt`. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"editable": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import datetime as dt\n",
|
||||
"import pytz\n",
|
||||
"\n",
|
||||
"NAIVE_DT = dt.datetime(2000, 1, 1, 10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you don't know the timezone name you're looking for, this may be helpful:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"editable": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for tz in pytz.all_timezones:\n",
|
||||
" print(tz)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now create `utc_dt`, `sydney_dt`, and `la_dt`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Your implementation here"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Let's verify that the solution is correct."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"editable": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"assert utc_dt.isoformat() == '2000-01-01T10:00:00+00:00'\n",
|
||||
"assert sydney_dt.isoformat() == '2000-01-01T21:00:00+11:00'\n",
|
||||
"assert la_dt.isoformat() == '2000-01-01T02:00:00-08:00'\n",
|
||||
"\n",
|
||||
"print('All good!')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user