This document contains a Jupyter notebook that provides exercises for users to practice Markdown and code cells. The Markdown exercises have the user write headings, paragraphs, lists and more. The code exercises have the user define variables, display values, use f-strings and loops to print out sentences with substituted names and heights. Functions are also practiced to write out personal data dictionaries.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
101 views7 pages
4 Practice - Introduction - Solutions - Ipynb
This document contains a Jupyter notebook that provides exercises for users to practice Markdown and code cells. The Markdown exercises have the user write headings, paragraphs, lists and more. The code exercises have the user define variables, display values, use f-strings and loops to print out sentences with substituted names and heights. Functions are also practiced to write out personal data dictionaries.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7
{
"cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Practice Notebook\n", "\n", "## Introduction to the Jupyter Notebook\n", "\n", "In this notebook you will practice with the basic knowledge about the Markdown and the Code (Python) cells. You will find some instructions that will guide you." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Markdown Cells\n", "\n", "In the following cells you will practice what you have learned about the Markdown language. Notice that you can add more cells when needed using the toolbar. **Be careful, cells can be deleted too!!**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1:\n", "\n", "Transform the cell below in a markdown cell and then:\n", "\n", "- Write a heading\n", "- A subheading (level 2 heading)\n", "- A paragraph of text\n", "- Another subheading\n", "- Two paragraphs of text. The second one should include a newline.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Heading\n", "\n", "## This is the subheading level 2\n", "\n", "We are going to write a paragraph of text. This is long enough but I want to use several sentences. Three should be enough.\n", "\n", "## This is the second subheading\n", "\n", "We are going to write a paragraph of text.\\\n", "This is long enough but I want to use several sentences. Three should be enough.\n", "\n", "We are going to write a paragraph of text. <br /> This is long enough but I want to use several sentences. Three should be enough.\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2:\n", "\n", "Transform the cell below in a markdown cell and write two paragraphs separated by a horizontal rule. The first paragraph must contain a sentence in bold characters and the second paragraph must contain a sentence with italic characters." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to write a paragraph of text. **This is long enough but I want to use several sentences.** Three should be enough.\n", "\n", "---\n", "\n", "We are going to write a paragraph of text. _This is long enough but I want to use several sentences._ Three should be enough." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3:\n", "\n", "Write an unordered list" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- One element\n", "- Two elements\n", "- Three elements" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4:\n", "\n", "Write an ordered list" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Hello\n", "2. Darling\n", "2. Third element" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 5:\n", "\n", "Write a nested list combining ordered and unordered lists. The list must have a depth of 4 levels. In the second level you need to include three different ordered lists with at least 3 elements each." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Unordered\n", " 1. ordered\n", " - Level 3\n", " - Level4\n", " - Level 3\n", " 2. ordered\n", " 3. ordered\n", "- Unordered\n", " 1. ordered\n", " 2. ordered\n", " 3. ordered\n", "- Unordered\n", " 1. ordered\n", " 2. ordered\n", " 3. ordered\n", "- Unordered\n", "- Unordered" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code Cells\n", "\n", "In the following cells you will practice what you have learned about Python code and syntax." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 6:\n", "\n", "Define a variable called 'height' which contains a floating point number 1.98" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "height = 1.98" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 7:\n", "\n", "Define a variable called 'name' which contains a string" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "name = \"Victoria\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 8:\n", "\n", "Display the values of the two variables that you defined." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Victoria\n", "1.98\n" ] } ], "source": [ "print(name)\n", "print(height)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 9:\n", "\n", "Define an f-string that calls the different variables that you have defined before and display it. The floating point number must be displayed with one decimal." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Victoria has a height of 2.0m.'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fstring = f\"{name} has a height of {height:.1f}m.\"\n", "\n", "fstring" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 10:\n", "\n", "Define a list with three strings representing names and another with three numbers representing heights. Use a for-loop to print the following sentence three times where the words NAME and HEIGHT are replaced by the strings in the list that you defined.\n", "\n", "> NAME's height is HEIGHTm." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Alice's height is 1.75m.\n", "Bob's height is 1.82m.\n", "Michael's height is 1.68m.\n" ] } ], "source": [ "names_list = [\"Alice\", \"Bob\", \"Michael\"]\n", "heights_list = [1.75, 1.82, 1.68]\n", "\n", "for i in range(3):\n", " \n", " name = names_list[i]\n", " height = heights_list[i]\n", " fstring = f\"{name}'s height is {height}m.\"\n", " \n", " print(fstring)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 11:\n", "\n", "Write a list, that contains three dictionaries with keys \"name\" and \"height\" and the values that you like. Write a python function that takes as variable a list with the structure above and prints for each entry in the list a string\n", "\n", "> NAME's height is HEIGHTm.\n", "\n", "with NAME and HEIGHT substituted appropriately" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Alice's height is 1.75m.\n", "Bob's height is 1.82m.\n", "Michael's height is 1.68m.\n" ] } ], "source": [ "personal_data = [{\"name\": \"Alice\",\"height\": 1.75}, {\"name\": \"Bob\",\"height\": 1.82}, {\"name\": \"Michael\", \"height\": 1.68}]\ n", "\n", "def write_personal_data(data):\n", " \n", " for dictionary in data:\n", " \n", " name = dictionary[\"name\"]\n", " height = dictionary[\"height\"]\n", " fstring = f\"{name}'s height is {height}m.\"\n", " \n", " print(fstring)\n", " \n", "write_personal_data(personal_data)\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }