diff --git a/01-intro-to-computing.Rmd b/01-intro-to-computing.Rmd index 536cced..99cfee8 100644 --- a/01-intro-to-computing.Rmd +++ b/01-intro-to-computing.Rmd @@ -105,17 +105,6 @@ add(18, add(21, 65)) Remember that the Python language is supposed to help us understand what we are writing in code easily, lending to *readable* code. Therefore, it is sometimes useful to come up with operations that is easier to read. (Most functions in Python are stored in a collection of functions called **modules** that needs to be loaded. The `import` statement gives us permission to access the functions in the module "operator".) -### Data types - -Here are some common data types we will be using in this course. - -| Data type name | **Data type shorthand** | **Examples** | -|----------------|:-----------------------:|:-----------------------:| -| Integer | int | 2, 4 | -| Float | float | 3.5, -34.1009 | -| String | str | "hello", "234-234-8594" | -| Boolean | bool | True, False | - ### Function machine schema A nice way to summarize this first grammar structure is using the function machine schema, way back from algebra class: @@ -128,6 +117,17 @@ Here are some aspects of this schema to pay attention to: - A function can have different kinds of inputs and outputs - it doesn't need to be numbers. In the `len()` function, the input is a String, and the output is an Integer. We will see increasingly complex functions with all sorts of different inputs and outputs. +### Data types + +Here are some common data types we will be using in this course. + +| Data type name | **Data type shorthand** | **Examples** | +|----------------|:-----------------------:|:-----------------------:| +| Integer | int | 2, 4 | +| Float | float | 3.5, -34.1009 | +| String | str | "hello", "234-234-8594" | +| Boolean | bool | True, False | + ## Grammar Structure 2: Storing data types in the Variable Environment To build up a computer program, we need to store our returned data type from our expression somewhere for downstream use. We can assign a variable to it as follows: @@ -175,7 +175,7 @@ Let's look at functions a little bit more formally: A function has a **function > > The output of functions is called the **returned value**. -Often, we will use multiple functions in a nested way, and it is important to understand how the Python console understand the order of operation. We can also use paranthesis to change the order of operation. Think about what the Python is going to do step-by--step in the lines of code below: +Often, we will use multiple functions in a nested way, and it is important to understand how the Python console understand the order of operation. We can also use parenthesis to change the order of operation. Think about what the Python is going to do step-by--step in the lines of code below: ```{python} max(len("hello"), 4) @@ -221,11 +221,11 @@ And there is an operational equivalent: We will mostly look at functions with input arguments and return types in this course, but not all functions need to have input arguments and output return. Let's look at some examples of functions that don't always have an input or output: -| Function call | What it takes in | What it does | Returns | +| Function call | What it takes in | What it does | Returns | |----------------|----------------|-------------------------|----------------| -| [`pow(a, b)`](https://docs.python.org/3/library/functions.html#pow) | integer `a`, integer `b` | Raises `a` to the `b`th power. | Integer | -| [`print(x)`](https://docs.python.org/3/library/functions.html#print) | any data type `x` | Prints out the value of `x` to the console. | None | -| [`dir()`](https://docs.python.org/3/library/functions.html#dir) | Nothing | Gives a list of all the variables defined in the environment. | List | +| [`pow(a, b)`](https://docs.python.org/3/library/functions.html#pow) | integer `a`, integer `b` | Raises `a` to the `b`th power. | Integer | +| [`time.sleep(x)`](https://docs.python.org/3/library/time.html#time.sleep) | Integer `x` | Waits for `x` seconds. | None | +| [`dir()`](https://docs.python.org/3/library/functions.html#dir) | Nothing | Gives a list of all the variables defined in the environment. | List | ## Tips on writing your first code diff --git a/03-data-wrangling1.Rmd b/03-data-wrangling1.Rmd index eeac127..53dea24 100644 --- a/03-data-wrangling1.Rmd +++ b/03-data-wrangling1.Rmd @@ -169,7 +169,7 @@ metadata.OncotreeLineage.value_counts().plot(kind = "bar") plt.show() ``` -(The `plt.figure()` and `plt.show()` functions are used to render the plots on the website, but you don't need to use it for your exercises - yet. We will discuss this in more detail during our week of data visualization.) +(The `plt.figure()` and `plt.show()` functions are used to render the plots on the website, but you don't need to use it for your exercises. We will discuss this in more detail during our week of data visualization.) #### Chained function calls diff --git a/slides/images/function_machine.png b/slides/images/function_machine.png new file mode 100644 index 0000000..2bb7d9f Binary files /dev/null and b/slides/images/function_machine.png differ diff --git a/slides/lesson1_slides.html b/slides/lesson1_slides.html index 31ee4e5..de68197 100644 --- a/slides/lesson1_slides.html +++ b/slides/lesson1_slides.html @@ -307,6 +307,7 @@ } .reveal .slide:not(.center) { height: 100%; + overflow-y: auto; } .reveal .slide.scrollable { overflow-y: auto; @@ -438,8 +439,8 @@

Goals of the course

-
-

Culture of the course

+
+

Culture of the course (1/3)

  • Challenge: We are learning on the job, but you already have a full-time job
  • @@ -455,54 +456,53 @@

    Culture of the course

  • You should understand the gist of the material with class time, but mastery takes practice and practice.
-
+
+
+

Culture of the course (2/3)

-
    -
  • We learn and work better with our peers.
  • +
  • We learn and work better with our peers.
    -
  • You might make a new friend, or two. 😄
  • +
  • You might make a new friend, or two. 😄
-
+
+
+

Culture of the course (3/3)

-
    -
  • Curate content during open community sessions and office hours based on your inputs.
  • +
  • Curate content during open community sessions and office hours based on your inputs.
-
-

Format of the course

+
+

Code of Conduct

    -
  • 6 classes: April 17, 24, May 1, 8, 15, 22
  • +
  • Be considerate in speech and actions, and actively seek to acknowledge and respect the boundaries of other members.
    -
  • Streamed online, recordings will be available.
  • +
  • Be respectful - Disagreements happen, but do not require poor behavior or poor manners. If someone asks you to stop, then stop.
    -
  • 1-2 hour exercises after each session are strongly encouraged as they provide practice.

  • -
  • Optional time to work on exercises together on Fridays Noon - 1pm PT.

  • +
  • Refrain from demeaning, discriminatory, or harassing behavior and speech.
-
    -
  • Online discussion via Slack.
  • -
+

The full CoC can be found here.

@@ -522,20 +522,58 @@

Content of the course

    -
  1. Data wrangling 2
  2. +
  3. Community Session 1 (optional)
    -
  1. Data visualization
  2. +
  3. Data wrangling 2
    -
  1. Loading your own data in, celebratory lunch!!
  2. +
  3. Data visualization
  4. +
+
+
+
    +
  1. Community Session 2 (optional)
  2. +
+
+
+
    +
  1. Putting it together: preview for code-a-thon (Tuesday Nov. 12)
  2. +
+
+
+
    +
  1. Code-a-thon: Friday Nov. 22
+
+

Format of the course

+
+
    +
  • Streamed online, recordings will be available.
  • +
+
+
+
    +
  • 1-2 hour exercises after each session are encouraged for practice.
  • +
+
+
+
    +
  • Optional time to work on exercises together on Fridays 10am - 11am PT.
  • +
+
+
+
    +
  • Online discussion via Slack.
  • +
+
+

What is a computer program?

@@ -549,20 +587,23 @@

What is a computer program?

-

We will focus on English <-> Programming Code for R Interpreter in this class.

+

We will focus on English <-> Programming Code for Python Interpreter in this class.

Another way of putting it: How we organize ideas <-> Instructing a computer to do something.

-
-

Setting up Posit Cloud and trying out your first analysis!

-

What’s the connection between English <-> Programming Code for R Interpreter?

+
+

Setting up Google Classroom and Colab and trying out your first analysis!

+
    +
  • Google Classroom invitation link.

  • +
  • Classwork -> Week 1 Classwork -> Week 1 Classwork.ipynb

  • +

Break

A pre-course survey:

-

https://forms.gle/Hr59ZbAan1JTumCa7

+

https://forms.gle/zFZ3VB1QZ84Y8Uef6

Grammar Structure 1: Evaluation of Expressions

@@ -573,7 +614,7 @@

Grammar Structure 1: Evaluation of Expressions

    -
  • Operations and functions take in data types and return another data type.
  • +
  • Functions and operations take in data types, do something with them, and return another data type.
@@ -584,55 +625,55 @@

Grammar Structure 1: Evaluation of Expressions

Examples

-
-
18 + 21
+
+
18 + 21
-
-
-
[1] 39
+
+
+
39
-
-
max(18, 21)
+
+
max(18, 21)
-
-
-
[1] 21
+
+
+
21
-
-
max(18 + 21, 65)
+
+
max(18 + 21, 65)
-
-
-
[1] 65
+
+
+
65
-
-
18 + (21 + 65)
+
+
18 + (21 + 65)
-
-
-
[1] 104
+
+
+
104
-
-
nchar("ATCG")
+
+
len("ATCG")
-
-
-
[1] 4
+
+
+
4
-
-

Data types

+
+

Function machine from algebra class

+ +Function machine from algebra class.
    +
  • A programmer should not need to know how the function or operation is implemented in order to use it - this emphasizes abstraction and modular thinking.
  • +
+
    -
  • Numeric: 18, -21, 65, 1.25

  • -
  • Character: “ATCG”, “Whatever”, “948-293-0000”

  • -
  • Logical: TRUE, FALSE

  • +
  • A function can have different kinds of inputs and outputs - it doesn’t need to be numbers.
+
+
+
+

Data types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data type nameData type shorthandExamples
Integerint2, 4
Floatfloat3.5, -34.1009
Stringstr“hello”, “234-234-8594”
BooleanboolTrue, False

Grammar Structure 2: Storing data types in the environment

To build up a computer program, we need to store our returned data type from our expression somewhere for downstream use.

-
-
x = 18 + 21
+
+
x = 18 + 21
-
+
@@ -718,7 +786,6 @@

Grammar Structure 2: Storing data types in the environment

Evaluate the expression to the right of =.

Bind variable to the left of = to the resulting value.

The variable is stored in the environment.

-

<- is okay too!

@@ -741,22 +808,33 @@

Grammar Structure 2: Storing data types in the environment

Downstream

Look, now x can be reused downstream:

-
-
x - 2
+
+
x - 2
-
-
-
[1] 37
+
+
+
37
-
-
y = x * 2
+
+
y = x * 2
 y
-
-
-
[1] 78
+
+
+
78
+
+
+
+
+

What’s the data type of a variable?

+
+
type(y)
+
+
+
+
int
@@ -764,7 +842,6 @@

Downstream

Grammar Structure 3: Evaluation of Functions

A function has a function name, arguments, and returns a data type.

-
@@ -774,54 +851,75 @@

Grammar Structure 3: Evaluation of Functions

Execution rule for functions:

-

Evaluate the function by its arguments, and if the arguments contain expressions, evaluate those expressions first.

-

The output of functions is called the returned value.

+

A function’s input arguments, when there’s more than one, can be specified by:

+
    +
  • The order the input given: pow(2, 3) is different than pow(3, 2).

  • +
  • The name of the input argument: pow(base=2, exp=3).

  • +
+

If the arguments contain expressions, evaluate those expressions first!

+
+
+

Examples

+
+
pow(2, 3)
-
-
-
sqrt(nchar("hello"))
+
+
+
8
-
-
-
[1] 2.236068
+
+
pow(base=2, exp=3)
+
+
+
8
-
-
-
(nchar("hello") + 4) * 2
-
-
-
[1] 18
+
+
pow(exp=3, base=2)
+
+
+
8
-
-
-

A programming language has following features:

-
    -
  • Grammar structure to construct expressions
  • -
+
+
max(len("hello"), 4)
+
+
+
+
5
+
-
-
    -
  • Combining expressions to create more complex expressions
  • -
+
+
+

Learning a new function

+
    +
  1. Function documentation
  2. +
+
?pow
+
+pow(base, exp, mod=None)
+Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments
+ 
+Some types, such as ints, are able to use a more efficient algorithm when
+invoked using the three argument form.
-
    -
  • Encapsulate complex expressions via functions to create modular and reusable tasks
  • -
+
    +
  1. Documents page of a Python Module
  2. +
+

Base Python documentation of pow

-
    -
  • Encapsulate complex data via data structures to allow efficient manipulation of data
  • -
+
    +
  1. Forums vetted by experts, such as SlackOverflow
  2. +
@@ -849,13 +947,9 @@

Tips on writing your first code

  • Ask for help!
-
-
-
-

That’s all!

-

Maybe see you Friday Noon - 1pm PT to practice together!

@@ -1069,44 +1163,6 @@

That’s all!

] }); - - -