0% found this document useful (0 votes)
1 views

Getting_Started_with_JupyterNotebook

This document is a lab guide for getting started with Jupyter Notebooks, covering the basics of code and markdown cells. It includes objectives, exercises, and examples to help users learn how to execute code, write comments, and format text using markdown. The lab is designed to take approximately 10 minutes to complete.

Uploaded by

verokozia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Getting_Started_with_JupyterNotebook

This document is a lab guide for getting started with Jupyter Notebooks, covering the basics of code and markdown cells. It includes objectives, exercises, and examples to help users learn how to execute code, write comments, and format text using markdown. The lab is designed to take approximately 10 minutes to complete.

Uploaded by

verokozia
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

{"cells":[{"cell_type":"markdown","id":"e153d6cd-3a69-4434-a847-

cb901255953b","metadata":{},"outputs":[],"source":["<p style=\"text-
align:center\">\n"," <a href=\"https://skills.network/?
utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006
555&utm_id=NA-SkillsNetwork-Channel-
SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0101ENSkillsNetwork19487395-2022-01-
01\" target=\"_blank\">\n"," <img src=\"https://cf-courses-data.s3.us.cloud-
object-storage.appdomain.cloud/assets/logos/SN_web_lightmode.png\" width=\"200\"
alt=\"Skills Network Logo\" />\n"," </a>\n","</p>\n","\n","# Lab: Getting
Started with Jupyter Notebooks\n","\n","Estimated time needed: **10** minutes\n","\
n","## Objectives\n","\n","After completing this lab, you will be able to:\n","*
Get an overview of code and markdown cells\n","* Execute an existing code cell\
n","* Insert and delete a code cell\n","* Write comments in Python\n","*
Create and use Markdown cells\n"]},{"cell_type":"markdown","id":"a88e5622-cf4c-
4654-b106-afca8e02a431","metadata":{},"outputs":[],"source":["# Overview of Code
and Markdown Cells\n","\n","A Jupyter notebook usually has many cells. A cell is an
input field that allows you to enter multiple lines of text.\n","\n","There are two
types of cells in a Jupyter notebook:\n","\n","* Markdown cell\n","* Code cell\
n","\n","<b>Markdown cell</b>:\n","<div style=\"padding-left: 30px;\">\n","Use
Markdown cells to include text that should not be read and executed as language-
specific code. You can include rich-text code descriptions of your code by entering
and formatting the text in a Markdown cell.<br/>\n","\n","Markdown cells allow us
to apply several formatting options with the Markdown language: \n","\n","*
Headings\n","* Links\n","* Tables\n","* Paragraphs\n","* Bold text\n","* Lists\
n","* And more\n","\n","</div>\n","\n"]},{"cell_type":"markdown","id":"3f061bd9-
9d07-4c7c-89d9-f52dcec8570f","metadata":{},"outputs":[],"source":["## This is an
example of a markdown cell\n"]},{"cell_type":"markdown","id":"8c485a62-0577-47ce-
9f00-567b2ce577a1","metadata":{},"outputs":[],"source":["<b>Code cell</b>\n","<div
style=\"padding-left: 30px;\">\n","Use Code cells when you want to write and modify
code. The default cell displayed in a Jupyter notebook is a Code cell.\n"]},
{"cell_type":"code","id":"ce3fc061-fcff-45b8-a35f-05388808f3cc","metadata":
{},"outputs":[],"source":["# This is an example of a code cell"]},
{"cell_type":"markdown","id":"e172001b-f362-4789-8936-949dac7983c6","metadata":
{},"outputs":[],"source":["# Exercise 1\n","## Say \"Hello\" to the world in
Python\n"]},{"cell_type":"markdown","id":"50e99f1c-ecde-433f-95dd-
45d36274eba1","metadata":{},"outputs":[],"source":["When learning a new programming
language, it is customary to start with a \"hello world\" example. As simple as it
is, this one line of code will ensure that we know how to print a string in output
and how to execute code within cells in a notebook.\n"]},
{"cell_type":"markdown","id":"218b7592-65e4-44f4-a187-3d00bf4c52fe","metadata":
{},"outputs":[],"source":["<hr/>\n","<div class=\"alert alert-success
alertsuccess\" style=\"margin-top: 20px\">\n","💡 [Tip]: To execute the Python code
in the code cell below, click the cell to select it and press <kbd>Shift</kbd> +
<kbd>Enter</kbd>.\n","</div>\n","<hr/>\n","\n"]},
{"cell_type":"code","id":"f8298881-5cd7-4bd8-b7fa-e28c6a169486","metadata":
{},"outputs":[],"source":["# Try your first Python output. Click here and press
Shift + Enter to execute the cell\n\n'Hello, Python!'"]},
{"cell_type":"markdown","id":"334e3cde-1639-4eb2-8b95-05ba70796a73","metadata":
{},"outputs":[],"source":["After executing the cell above, you should see that
Python prints <code>Hello, Python!</code>. Congratulations on running your first
Python code! \n"]},{"cell_type":"markdown","id":"d30fd0d1-f360-4f4e-9711-
6a01dfc6f596","metadata":{},"outputs":[],"source":["### Display an Integer\n"]},
{"cell_type":"code","id":"cba500f4-73c6-48a6-98e4-58bd92f61b1a","metadata":
{},"outputs":[],"source":["# Print an integer\n\n2"]},
{"cell_type":"markdown","id":"2c01e7d7-bbe2-4c8d-b2bf-3c13c32a263d","metadata":
{},"outputs":[],"source":["### Mathematical Operations\n","\n","Now, run the
following cells and observe the output of the mathematical operations.\n","\
n","<img src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/run_1.png\">\
n"]},{"cell_type":"code","id":"b598c7df-39c4-4b92-9614-66ec26d7c029","metadata":
{},"outputs":[],"source":["# Addition operation\n2+2"]},
{"cell_type":"code","id":"0effcd53-930b-44d6-b6b4-48b9bf519490","metadata":
{},"outputs":[],"source":["# Multiplication operation\n2.5*3.5"]},
{"cell_type":"markdown","id":"d894567b-2783-400a-a3a5-5389fe7cdf37","metadata":
{},"outputs":[],"source":["# Exercise 2\n","### Create a new cell and execute it.\
n","\n","In your Jupyter notebook, click the **+** symbol to insert a new cell.\
n","\n","<img src=\"https://cf-courses-data.s3.us.cloud-object-
storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/
Labs_V4/images/insertcodecell.jpg\">\n","\n"]},{"cell_type":"code","id":"ec5700c7-
af0b-402a-9c60-2062d8ac022e","metadata":{},"outputs":[],"source":["# Create a new
code cell below this cell and type in 4.5 and execute it"]},
{"cell_type":"markdown","id":"5c6e615e-60e1-4809-a52f-f674f6f90c59","metadata":
{},"outputs":[],"source":["<details><summary>Click here for the solution</summary>\
n","\n","```python\n","4.5\n","\n","```\n","The output looks as:\n","\n","<img
src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/
exe_sol.png\">\n","\n","</details>\n"]},{"cell_type":"markdown","id":"4a5caf0b-
2350-4dec-ab49-3c89111c9df3","metadata":{},"outputs":[],"source":["# Exercise 3\
n","\n","### Delete a cell in Jupyter Notebook.\n","\n","Place your cursor at the
cell given below. Click **Edit** and select **Delete cells**.\n","\n","<img
src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/
deletecells1.jpg\">\n","\n"]},{"cell_type":"code","id":"ce4762bd-9a8a-4446-81c6-
f17baabd695b","metadata":{},"outputs":[],"source":["## Select this cell and
delete"]},{"cell_type":"markdown","id":"a6978194-0e5d-4d76-801f-
0598542f1d13","metadata":{},"outputs":[],"source":["The highlighted cell gets
deleted.\n"]},{"cell_type":"markdown","id":"75ce91a9-9eaf-400a-bfe4-
7f0d72cfa1c9","metadata":{},"outputs":[],"source":["# Exercise 4\n","### Writing
comments in Python\n","\n","<p>\n"," In addition to writing code, note that it's
always a good idea to add comments to your code. It will help others understand
what you were trying to accomplish (why you wrote a given code snippet). Not only
does this help <strong>other people</strong> understand your code, but it can also
serve as a reminder <strong>to you</strong> when you come back to it weeks or
months later.</p>\n","\n","<p>\n"," To write comments in Python, use the number
symbol <code>#</code> before writing your comment. Python will ignore everything
past the <code>#</code> on a given line when you run your code.\n","</p>\n"]},
{"cell_type":"code","id":"a27bcebd-43fd-442e-864c-878d3465be65","metadata":
{},"outputs":[],"source":["# Execute this cell by clicking Shift + Enter\n\n2+3"]},
{"cell_type":"markdown","id":"66b54183-ae38-4d50-b945-49e9623f7258","metadata":
{},"outputs":[],"source":["After executing the above cell, you will find that the
output <code>5</code> is generated on executing <code>2+3</code>\n"]},
{"cell_type":"code","id":"aa5e85d2-3927-4ca5-934a-71d8e1cea2b2","metadata":
{},"outputs":[],"source":["# Execute this cell by clicking Shift + Enter\n# 2+3"]},
{"cell_type":"markdown","id":"5ba27e82-92de-409e-96e8-85e15822ebc1","metadata":
{},"outputs":[],"source":["<hr/>\n","<div class=\"alert alert-success
alertsuccess\" style=\"margin-top: 20px\">\n","<p>\n"," \n","After executing the
above cell code <code>2+3</code> output <code>5</code> is not generated because
<code>2+3</code> was preceeded by the number sign (<code>#</code>) and is treated
as a comment.\n","</strong>\n","</p>\n","\n","</div>\n"]},
{"cell_type":"markdown","id":"dc478018-8ef8-40cb-a79d-14b73d3efe98","metadata":
{},"outputs":[],"source":["# Exercise 5\n","\n","### Using markdown cells\n","\
n","Change the **Code** cell below to **Markdown** cell from the dropdown. \n","\
n","<img src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/
codetomarkdown.jpg\">\n","\n","Type in the text as **My First Markdown**\n"]},
{"cell_type":"code","id":"9a6859af-55ba-47fb-8ce0-50e3dbbda20c","metadata":
{},"outputs":[],"source":["# Change code cell to Markdown and write the text"]},
{"cell_type":"markdown","id":"d183a27a-4d0b-45aa-ab42-2f5c5635b29e","metadata":
{},"outputs":[],"source":["<details><summary>Click here for the solution</summary>\
n","\n","```python\n","My First Markdown\n","\n","```\n","The output look as:\n","\
n","<img src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/
outputmkdown.png\">\n","</details>\n"]},{"cell_type":"markdown","id":"1e1b0199-
9500-48b0-b504-14680d5d0b8f","metadata":{},"outputs":[],"source":["Your markdown
cell should now be rendered! _To edit your markdown cell, double-click anywhere
within the cell._ \n"]},{"cell_type":"markdown","id":"f427ad89-c91d-478a-90fe-
133d2fa864cc","metadata":{},"outputs":[],"source":["# Practice Exercises\n"]},
{"cell_type":"markdown","id":"f0e4f85f-2400-48a5-8698-1003c980dc80","metadata":
{},"outputs":[],"source":["### Task 1: Insert a new Markdown cell with the text as
**Evaluating
Basic Arithmetic Expression**.\n"]},{"cell_type":"markdown","id":"82a376db-6ddb-
4d48-bd05-12e5f9d507ac","metadata":{},"outputs":[],"source":
["<details><summary>Click here for the solution</summary>\n","Evaluating Basic
Arithmetic Expression\n","\n","Here we will be evaluating a basic arithmetic
expression containing addition and multiplication operations.\n","\n","</details>\
n"]},{"cell_type":"markdown","id":"4c987384-776d-4ec6-8029-
1e6a5ef997ef","metadata":{},"outputs":[],"source":["### Task 2: Insert a new code
cell below and use this **expression** <code>(20+5)*4</code> and **execute** it.\
n"]},{"cell_type":"markdown","id":"f4e3f2f9-df0a-4581-9b18-
c0c73dab87dc","metadata":{},"outputs":[],"source":["<details><summary>Click here
for the solution</summary>\n","\n","```python\n","(20+5)*4\n","\n","```\n","\
n","</details>\n"]},{"cell_type":"markdown","id":"c3364124-a737-4713-bf3a-
7faf4570fd63","metadata":{},"outputs":[],"source":["#### Task 3: In the cell below,
add a comment as **Displaying a string message**. Add the line <code>\"Let us
explore python without coding.\" </code>below the comment and execute it \n"]},
{"cell_type":"code","id":"234bdf50-a13c-4189-9e1e-61b2c8bd0ceb","metadata":
{},"outputs":[],"source":["## Write your markdown here"]},
{"cell_type":"markdown","id":"1d1c9c6e-8676-4e01-b309-f10943dac309","metadata":
{},"outputs":[],"source":["<details><summary>Click here for the solution</summary>\
n","\n","```python\n","# Displaying a string message\n","\"Let us explore python
without coding\"\n","\n","```\n","\n","</details>\n"]},
{"cell_type":"markdown","id":"e866b351-b78b-4ac1-a3b4-83a4dc6c0ee9","metadata":
{},"outputs":[],"source":["#### (Bonus) Task 4: Split the code cell below after
```1+1```\n"]},{"cell_type":"code","id":"3a024866-5198-44eb-8e07-
a3ac95a1a1d0","metadata":{},"outputs":[],"source":["## Click after 1+1 in this cell
and split it\n1+1\n2*2"]},{"cell_type":"markdown","id":"5501b8f8-1fc2-4ea0-993d-
e2d250a3fb9c","metadata":{},"outputs":[],"source":["<details><summary>Click here
for the hint</summary>\n","\n","Use Edit menu and select Split Cell\n","\n","<img
src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/
IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/Labs_V4/images/
splihint.png\">\n","\n","</details>\n"]},{"cell_type":"markdown","id":"ab3c6fba-
38ec-47e7-b3b3-476ad182d17b","metadata":{},"outputs":[],"source":
["<details><summary>Click here for the solution</summary>\n","\n","Click 2nd line
and aplit it using Split Cell from Edit menu.\n","\n","<img src=\"https://cf-
courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-
DS0105EN-SkillsNetwork/labs/Labs_V4/images/split1.png\">\n","\n","The solutions
looks as:\n","\n","<img src=\"https://cf-courses-data.s3.us.cloud-object-
storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0105EN-SkillsNetwork/labs/
Labs_V4/images/splisol.png\">\n","\n","\n","</details>\n"]},
{"cell_type":"markdown","id":"b9f62359-def2-4763-baf3-c4f9ebec306e","metadata":
{},"outputs":[],"source":["### Thank you for completing this lab!\n"]},
{"cell_type":"markdown","id":"fd63abb9-aeb9-4403-8eca-f5be4c0af589","metadata":
{},"outputs":[],"source":["## Author\n","\n","[Lakshmi
Holla](https://www.linkedin.com/in/lakshmi-holla-b39062149/?
utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006
555&utm_id=NA-SkillsNetwork-Channel-
SkillsNetworkCoursesIBMDeveloperSkillsNetworkDS0105ENSkillsNetwork984-2022-01-01)\
n","\n","[Malika Singla](https://www.linkedin.com/in/malika-goyal-04798622/?
utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006
555&utm_id=NA-SkillsNetwork-Channel-
SkillsNetworkCoursesIBMDeveloperSkillsNetworkDS0105ENSkillsNetwork984-2022-01-01)\
n","\n","\n","\n","<!-- ## Change Log\n","\n","| Date (YYYY-MM-DD) | Version |
Changed By | Change Description |\n","| ----------------- | -------
| ---------- | ---------------------------------- |\n","| 2022-09-30 | 0.1
| Lakshmi Holla | Created Initial version |-->\n","\n","\n","## <h3
align=\"center\"> © IBM Corporation 2022. All rights reserved. <h3/>\
n"]}],"metadata":{"kernelspec":{"name":"python","display_name":"Python
(Pyodide)","language":"python"},"language_info":{"codemirror_mode":
{"name":"python","version":3},"file_extension":".py","mimetype":"text/x-
python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","
version":"3.8"},"prev_pub_hash":"8c2823db202ee595729269c17f2e7229c2d298d6cfc3e537a4
2d730b11ae4674"},"nbformat":4,"nbformat_minor":4}

You might also like