Lecture 3
Expressions
DATA 8
Summer 2017
Slides created by John DeNero (denero@berkeley.edu) and Sam Lau (samlau95@berkeley.edu)
Announcements
Review: Cause & Effect
Comparison
Confounding
Randomize!
Expressions
Programming Languages
(Demo)
Arithmetic Operators
| Operation | Operator | Example | Value | 
| Addition | + | 2 + 3 | 5 | 
| Subtraction | - | 2 - 3 | -1 | 
| Multiplication | * | 2 * 3 | 6 | 
| Division | / | 7 / 3 | 2.66667 | 
| Remainder | % | 7 % 3 | 1 | 
| Exponentiation | ** | 2 ** 0.5 | 1.41421 | 
Example: Slopes
Much better
(Demo)
Numbers
(Demo)
Ints and Floats
Python has two real number types
An int never has a decimal point; a float always does
A float might be printed using scientific notation
Three limitations of float values:
Discussion Question
Rank the results of the following expressions in order from least to greatest
Names
Assignment Statements
more_than_1 = 2 + 3
Name
Any expression
(Demo)
Exponential Growth
Growth Rate
x * (1 + g)
x * (1 + g) ** t
(after/before) ** (1/t) - 1
(Demo)
Ebola Epidemic, Sept. 2014
Source: Columbia Prediction of Infectious Diseases, World Health Organization
"It's spreading and growing exponentially," President Obama said.
"This is a disease outbreak that is advancing in an exponential fashion," said Dr. David Nabarro, who is heading the U.N.'s effort against Ebola.
A Frightening Curve: �How Fast Is The Ebola Outbreak Growing?