Data 8R Summer 2017 1

Intro to Python Discussion 2: June 19, 2017

Express Yourself!

An expression describes to the computer how to combine pieces of data. Many expressions form computer programs. Ex. >>> 1 + 4 ... 5 1.1

Write an expression to get to 2017. (Bonus Challenge: Try to use the numbers 1 through 9) 9 * 8 * 7 * (6 - 5) * 4 + (3 - 2) * 1

1.2

Write an expression to get to your birth year. >>> 3 ** 2 * 111 + 999

2

To Float or not to Float

Integers are called int values in Python - they can only represent whole numbers. Any number that has decimal point values is called a float. 2.1

Are these expressions floats or ints? It’s up to you to decide! >>> 2 + 3 * 4 >>> (3 / 1) >>> (2 / 4) + 3

int float float

3

Assign and Rate

We can assign names to values in Python using assignment statements: >>> a = 10 >>> a ... 10 3.1

Mike had a tremendous growth spurt over the past year. Find his growth rate over this 1 year. (Hint: The Growth Rate is the absolute difference between the final and initial levels divided by the initial value)

2

Intro to Python

>>> initial_height = 92 >>> final_height = 138 >>> growth_rate = ?

>>> >>> ... >>> >>> ...

4

change = final_height - initial_height change 46 growth_rate = change / initial_height growth_rate * 100 50%

Call and Response

Call expressions invoke functions, which are defined expressions (ex. add is a function). The name of the function is in front of the opening parentheses, and the expressions in parentheses are the inputs. Ex. >>> add(15, add(20, 15))

Remember: Because the inputs to a call expression are expressions themselves, you can have another call expression as an input. Additionally, remember that in Python we evaluate from left to right. 4.1

What’s the output? >>> from operator import add, sub, mul >>> mul(4, sub(3, 1)) >>> add(sub(mul(2, 3), 2), 3) >>> float_num = 2.3 >>> round(2 - float_num) >>> rounded_num = round(4.4 - 1) >>> max(2, abs(12 - 9), rounded_num)

6 16 9 7 0 3 Remember that the round function gives us an integer back!

5

Diagramming Calls

Diagram each of the following calls. An example is provided: 5.1

Example: >>> add(mul(2, 3), sub(6, 4))

Intro to Python

3

add(mul(2, 3), sub(6, 4)) =8

add

mul(2, 3) =6

sub(6,4) =2

... 8

All of the lines in our diagram are expressions - the line at the top is an addition expression, the mul a multiplication expression, and the sub a subtraction expression.

The following variables could be used in the diagrams: >>> x = 1 >>> z = 2 >>> y = 3 5.2

Infix Diagramming (** in Python is the power operator) ex. >>> 2 ** 3 ... 8 >>> 5 + z ** y - y / z * 6

>>> 5 + (z ** y) - (y / z) * 6

5 + (z ** y) - (y / z) * 6 =10.0

5

(z ** y) =9.0

z =3

y =2

(y / z) * 6 =4.0

(y / z) =0.666

y =2

6

z =3

... 10.0

Remember that when you divide, you will always get a float back.

4

5.3

Intro to Python

Call Diagramming The function truediv operates like the \ sign and the pow function operates like **. >>> sub(add(5, pow(z, y)), mul(truediv(y, z), 6))

sub(add(5, pow(z, y)), mul(truediv(y, z), 6)) =10.0

sub

add(5, pow(z, y)) =14.0

add

5

mul(truediv(y, z), 6) =4.0

pow(z, y) =9.0

pow

z =3

mul

y =2

truediv(y, z) =0.666

truediv

y =2

6

z =3

... 10.0

Don’t dwell on the fact that the tree contains the function reference itself, because this is somewhat confusing early on.

5.4

Callception >>> mul(add(sub(max(y, z), x), z), y)

mul(add(sub(max(y, z), x), z), y) =10

mul

add(sub(max(y, z), x), z) =5

add

sub(max(y, z), x) =2

sub

max(y, z) =3

max

y =2

z =3

x =1

z =3

y =2

Intro to Python

... 10

5.5

Callception >>> (max(y, z) - x + z) * y

(max(y, z) - x + z) * y =10

(max(y, z) - x + z) =5

max(y, z) =3

max

... 10

y =2

z =3

y =2

5

Data 8R Intro to Python Summer 2017 1 Express Yourself! 2 ... - GitHub

An expression describes to the computer how to combine pieces of data. ... inputs to a call expression are expressions themselves, you can have another call ...

105KB Sizes 0 Downloads 265 Views

Recommend Documents

Data 8R Intro to Python Summer 2017 1 Express Yourself! 2 ... - GitHub
Mike had a tremendous growth spurt over the past year. Find his growth rate over this 1 year. (Hint: The Growth Rate is the absolute difference between the final.

Data 8R Hypothesis Testing Summer 2017 1 Terminology 2 ... - GitHub
Jul 27, 2017 - simulated on a computer. ... From the histogram, it looks like the higher mean from gambling was not at all that unusual - it certainly could have.

Data 8R Intro to Visualizations Summer 2017 1 Similarity and ... - GitHub
Jun 27, 2017 - The chips that are present in your computer contain electrical components called transistors. ... Here's another attempt to improve the plot:.

Data 8R Plotting Functions Summer 2017 1 Midterm Review ... - GitHub
Data 8R. Plotting Functions. Summer 2017. Discussion 7: July 20, 2017. 1 Midterm Review. Question 4 ... function onto the table: Hint: Velocity = distance / time.

Data 8R Table Methods and Functions Summer 2017 1 ... - GitHub
Jul 18, 2017 - We have the dataset trips, which contains data on trips taken as part ofa ... def num_long_trips(cutoff): ... We want to see what the distribution of.

Data 8R Plotting Functions Summer 2017 1 Midterm Review ... - GitHub
Jul 20, 2017 - In physics calculations, we often want to have the data in terms of centimeters. Create a table called cm table that has the original data and a ...

Data 8R Table Methods and Functions Summer 2017 1 ... - GitHub
Jul 18, 2017 - Data 8R. Table Methods and Functions. Summer 2017. Discussion 7: ... its range - the difference between the highest value in the array and.

Data 8R Tables and more Visualizations Summer 2017 1 ... - GitHub
Jul 11, 2017 - At the same time, the researcher also records the number of ... A business has graphed the proportion of outputs in each year as a bar chart.

Data 8R Tables and more Visualizations Summer 2017 1 ... - GitHub
number of colds each volunteer gets. Is this an observational ... questions about it. A business has graphed the proportion of outputs in each year as a bar chart.

Data 8R Review of Table Methods Summer 2017 - GitHub
Jul 18, 2017 - We find that most trips have smaller length, but a few are very long. We want to see what the distribution of commute lengths looks like, and ...

Data 8R Review of Table Methods Summer 2017 - GitHub
Jul 18, 2017 - We also figure that commuters will be subscribers to the program, not one-time users. ... return np.mean(short_commute.column( Duration ) ...

Data 8R Data Types and Arrays Summer 2017 1 A Test of Skill - GitHub
1 A Test of Skill ... errors) of the following lines of Python code! >>> 6 / 3 ... Luckily, they've supplied a function named bar(labelArray, dataArray) to do.

Data 8R Data Types and Arrays Summer 2017 1 A Test of Skill - GitHub
Data 8R. Data Types and Arrays. Summer 2017. Discussion 4: July 6, 2017 ... Impress the squirrels with your knowledge of data types! .... 4 Data Manipulation.

Scientific python + IPython intro - GitHub
2. Tutorial course on wavefront propagation simulations, 28/11/2013, XFEL, ... written for Python 2, and it is still the most wide- ... Generate html and pdf reports.

lecture 2: intro to statistics - GitHub
Continuous Variables. - Cumulative probability function. PDF has dimensions of x-1. Expectation value. Moments. Characteristic function generates moments: .... from realized sample, parameters are unknown and described probabilistically. Parameters a

Intro to Webapp - GitHub
The Public Data Availability panel ... Let's look at data availability for this cohort ... To start an analysis, we're going to select our cohort and click the New ...

Intro to Webapp IGV - GitHub
Home Page or the IGV Github Repository. We are grateful to the IGV team for their assistance in integrating the IGV into the ISB-CGC web application.

Intro to Google Cloud - GitHub
The Cloud Datalab web UI has two main sections: Notebooks and Sessions. ... When you click on an ipynb file in GitHub, you see it rendered (as HTML).

EXPRESS YOURSELF 1.PDF
Sign in. Page. 1. /. 104. Loading… Page 1 of 104. Page 1 of 104. Page 2 of 104. Page 2 of 104. Page 3 of 104. Page 3 of 104. EXPRESS YOURSELF 1.PDF.

Intro to Google Cloud - GitHub
Now that you know your way around the Google Cloud Console, you're ready to start exploring further! The ISB-CGC platform includes an interactive Web App, ...

Intro to Webapp SeqPeek - GitHub
brought to you by. The ISB Cancer Genomics Cloud. An Introduction to the ISB-CGC Web App SeqPeek. Page 2. https://isb-cgc.appspot.com. Main Landing ...

Intro to Google Cloud - GitHub
known as “Application Default Credentials” are now created automatically. You don't really need to click on the “Go to. Credentials”, but in case you do the next ...

HW 2: Chapter 1. Data Exploration - GitHub
OI 1.8: Smoking habits of UK Residents: A survey was conducted to study the smoking habits ... create the scatterplot here. You can use ... Go to the Spurious Correlations website: http://tylervigen.com/discover and use the drop down menu to.

Innovative Projects Summer 2017 - GitHub
Jan 31, 2017 - 10. Page 2 http://nokiawroclaw.pl/ https://github.com/nokia-wroclaw/ .... Develop a tool that will notify person via android app that some system ...