from
client.api.notebook
import
Notebook
ok
=
Notebook(
'
lab01.ok
'
)
_
=
ok
.
auth(inline
=
True
)
=====================================================================
Assignment: Lab 1: Expressions
OK, version v1.12.5
=====================================================================
Open the following URL:
4

After logging in, copy the code from the web page and paste it into the box.
Then press the "Enter" key on your keyboard.
Paste your code here: STtbWYEgQgr3V4ORaV8qq4OkEiDtGl
Successfully logged in as [email protected]
When you finish an assignment, you need to submit it by running the submit command be-
low. It’s OK to submit multiple times, OK will only try to grade your final submission for each
assignment. Don’t forget to submit your lab assignment at the end of section, even if you haven’t
finished everything.
In [10]:
_
=
ok
.
submit()
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
Saving notebook... Saved
'
lab01.ipynb
'
.
Submit... 100% complete
Submission successful for user: [email protected]
URL:
3
2. Numbers
Quantitative information arises everywhere in data science.
In addition to representing com-
mands to print out lines, expressions can represent numbers and methods of combining numbers.
The expression
3.2500
evaluates to the number 3.25. (Run the cell and see.)
In [13]:
3.2500
Out[13]:
3.25
Notice that we didn’t have to
print
.
When you run a notebook cell, if the last line has a
value, then Jupyter helpfully prints out that value for you. However, it won’t print out prior lines
automatically.
In [12]:
print
(
2
)
print
(
3
)
4
2
3
5

Out[12]:
4
Above, you should see that 4 is the value of the last expression, 2 is printed, but 3 is lost forever
because it was neither printed nor last.
You don’t want to print everything all the time anyway. But if you feel sorry for 3, change the
cell above to print it.
3.1
2.1. Arithmetic
The line in the next cell subtracts. Its value is what you’d expect. Run it.
In [14]:
3.25 - 1.5
Out[14]:
1.75
Many basic arithmetic operations are built in to Python. The textbook section on
Expressions
describes all the arithmetic operators used in the course. The common operator that differs from
typical math notation is
**
, which raises one number to the power of the other. So,
2**3
stands
for 2
3
and evaluates to 8.
The order of operations is what you learned in elementary school, and Python also has paren-
theses. For example, compare the outputs of the cells below. Use parentheses for a happy new
year!
In [15]:
1+6*5-6*3**2*2**3/4*7
Out[15]:
-725.0
In [16]:
2+
(
6*5-
(
6*3
))
**2*
((
2**3
)
/4*7
)
Out[16]:
2018.0
In standard math notation, the first expression is
1
+
6
×
5
−
6
×
3
2
×
2
3
4
×
7,
while the second expression is
1
+ (
6
×
5
−
(
6
×
3
))
2
×
(
(
2
3
)
4
×
7
)
.
Question 2.1.1.
Write a Python expression in this next cell that’s equal to 5
×
(
3
10
11
)
−
50
1
3
+
2
.5
×
22
−
7
33
+
1. That’s five times three and ten elevenths, minus fifty and a third, plus two to the
power of half 22, minus 7 33rds plus 1. By "3
10
11
" we mean 3
+
10
11
, not 3
×
10
11
.

#### You've reached the end of your free preview.

Want to read all 18 pages?

- Fall '17
- Human height, Test Summary