# Review Questions

## Review Questions

#### Code cells and markdown cells

Q04.01 Run the following code in two different Jupyter notebook cells. Run one cell as a code cell. Run the other cell as a Markdown cell. Why is the output different?

# Problem Solving with Python


Q04.02 Run the following code in two different Jupyter notebook cells. Run one cell as a code cell. Run the other cell as a Markdown cell. Why is the output different?

print('Problem Solving with Python')


#### Markdown cells

Q04.10 Recreate the following headings in one Jupyter notebook markdown cell:

# BIG heading



Q04.11 Recreate the following table in one Jupyter notebook markdown cell:

Python Package Use
Jupyter jupyter notebooks
NumPy arrays
Matplotlib plots
PySerial serial communication

Q04.12 Recreate the following code block in one Jupyter notebook markdown cell:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline


Q04.12 Recreate the following bullet points in one Jupyter notebook markdown cell:

• markdown cell : markdown
• code cell: Python code
• raw NBConvert: LaTeX

Q04.13 Recreate the following list in one Jupyter notebook markdown cell:

1. Open Jupyter notebook
2. Write code
3. Restart Kernel & run all

Q04.14 Recreate two horizontal rules in a Jupyter notebook markdown cell. In between the horizontal rules write the text In between the lines like below:

In between the lines

Q04.15 Inside a Jupyter notebook markdown cell, make the word Red the color red, make the word Green, the color green, make the word Blue the color blue.

Q04.16 Create a warning box on the inside of a Jupyter notebook markdown cell that says:

Warning! Python counting starts at 0 and ends at n-1

#### LaTeX Math

Q04.20 Write the Pythagorean Theorem in a Jupyter notebook markdown cell using LaTeX math.

a^2 + b^2 = c^2

Q04.20 Write the formula for the area of a circle in a Jupyter notebook markdown cell using LaTeX math.

A = \pi r^2

Q04.20 Write the formula below in a Jupyter notebook Markdown cell using LaTeX math.

\int_{0}^{1} \frac{1}{y^3} dy

#### Code cells

Q04.31 Run the following in a Jupyter notebook code cell:

import this


Q04.32 Run the following in a Jupyter notebook code cell:

import sys
print(sys.version)


Q04.33 Run the following in a Jupyter notebook code cell:

import matplotlib.pyplot as plt
%matplotlib inline

plt.plot([1,3,6,10])
plt.show()


Q04.34 Run the following in a Jupyter notebook code cell. Move the slider back and forth:

from ipywidgets import interact
import ipywidgets as widgets

def func(x):
return x

interact(func, x=10);


#### Cell Magic

Q04.50 Create a file called hello.py in the same directory as your Jupyter notebook. Inside the file hello.py write the code below:

# hello.py

print("hello from the file")


Use the Jupyter notebook magic command %load to load the code from hello.py into your Jupyter notebook.

Q04.51 Create a file called hello.py in the same directory as your Jupyter notebook. Inside the file hello.py write the code below:

# hello.py

print("hello from the file")


Use the Jupyter notebook magic command %run to run the code from hello.py into your Jupyter notebook.

Q04.52 Run the code below in a Jupyter notebook code cell:

import os

print(os.getcwd())

%pwd


Why is the output of these two commands similar?

#### Getting Help

Q04.60 Use Python's dir() function in a Jupyter notebook code cell to find all the functions available in Python's math module. Remember to import math at the start of the code cell.

Q04.61 In a Jupyter notebook code cell, import math and run math.sqrt?. Copy the contents of the help you receive in a Jupyter notebook markdown cell.

Q04.61 In a Jupyter notebook code cell, import statistics and run statistics.mode?. Copy the examples from the help you receive in a Jupyter notebook code cell. Run the code cell.