Skip to content

Commit

Permalink
Render course
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 16, 2024
1 parent 865b918 commit 370115f
Show file tree
Hide file tree
Showing 13 changed files with 1,086 additions and 50 deletions.
50 changes: 36 additions & 14 deletions docs/01-intro-to-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ More importantly: **How we organize ideas \<-\> Instructing a computer to do som

Google Colab is a Integrated Development Environment (IDE) on a web browser. Think about it as Microsoft Word to a plain text editor. It provides extra bells and whistles to using Python that is easier for the user.

Let's open up the KRAS analysis in Google Colab. If you are taking this course while it is in session, the project name is probably named "KRAS Demo" in your Google Classroom workspace. If you are taking this course on your own time, open up...
Let's open up the KRAS analysis in Google Colab. If you are taking this course while it is in session, the project name is probably named "KRAS Demo" in your Google Classroom workspace. If you are taking this course on your own time, you can view it [here](https://colab.research.google.com/drive/1_77QQcj0mgZOWLlhtkZ-QKWUP1dnSt-_?usp=sharing).

![](images/colab.png){width="800"}

Today, we will pay close attention to:

- Python Console (Execution): Open it via View -\> Executed code history. You give it one line of Python code, and the console executes that single line of code; you give it a single piece of instruction, and it executes it for you.
- Python Console ("Executions"): Open it via View -\> Executed code history. You give it one line of Python code, and the console executes that single line of code; you give it a single piece of instruction, and it executes it for you.

- Notebook: in the central panel of the website, you will see Python code interspersed with word document text. This is called a Python Notebook (other similar services include Jupyter Notebook, iPython Notebook), which has chunks of plain text *and* Python code, and it helps us understand better the code we are writing.

- Variable Environment: Open it by clicking on the "{x}" button on the left-hand panel. Often, your code will store information in the Variable Environment, so that information can be reused. For instance, we often load in data and store it in the Variable Environment, and use it throughout rest of your Python code.

The first thing we will do is see the different ways we can run Python code. You can do the following:

1. Type something into the Python Console (Execution) and type enter, such as `2+2`. The Python Console will run it and give you an output.
1. Type something into the Python Console (Execution) and click the arrow button, such as `2+2`. The Python Console will run it and give you an output.
2. Look through the Python Notebook, and when you see a chunk of Python Code, click the arrow button. It will copy the Python code chunk to the Python Console and run all of it. You will likely see variables created in the Variables panel as you load in and manipulate data.
3. Run every single Python code chunk via Runtime -\> Run all.

Expand Down Expand Up @@ -142,7 +144,7 @@ add(18, add(21, 65))
## 104
```

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. (Because the `add()` function isn't typically used, it is not automatically available, so we used the import statement to load it in.)
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

Expand All @@ -161,7 +163,7 @@ A nice way to summarize this first grammar structure is using the function machi

Here are some aspects of this schema to pay attention to:

- A programmer should not need to know how the function is implemented in order to use it - this emphasizes abstraction and modular thinking, a foundation in any programming language.
- 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, a foundation in any programming language.

- 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.

Expand All @@ -182,11 +184,11 @@ If you enter this in the Console, you will see that in the Variable Environment,
>
> Bind variable to the left of `=` to the resulting value.
>
> The variable is stored in the Variable Environment.
> The variable is stored in the **Variable Environment**.
The Variable Environment is where all the variables are stored, and can be used for an expression anytime once it is defined. Only one unique variable name can be defined.

The variable is stored in the working memory of your computer, Random Access Memory (RAM). This is temporary memory storage on the computer that can be accessed quickly. Typically a personal computer has 8, 16, 32 Gigabytes of RAM. When we work with large datasets, if you assign a variable to a data type larger than the available RAM, it will not work. More on this later.
The variable is stored in the working memory of your computer, Random Access Memory (RAM). This is temporary memory storage on the computer that can be accessed quickly. Typically a personal computer has 8, 16, 32 Gigabytes of RAM.

Look, now `x` can be reused downstream:

Expand Down Expand Up @@ -214,30 +216,38 @@ type(y)
## <class 'int'>
```

We should give useful variable names so that we know what to expect! Consider `num_sales` instead of `y`.
We should give useful variable names so that we know what to expect! If you are working with sales data, consider `num_sales` instead of `y`.

## Grammar Structure 3: Evaluation of Functions

Let's look at functions a little bit more formally: A function has a **function name**, **arguments**, and **returns** a data type.

### Execution rule for functions:

> Evaluate the function by its arguments, and if the arguments are functions or contains operations, evaluate those functions or operations first.
> Evaluate the function by its arguments if there's any, and if the arguments are functions or contains operations, evaluate those functions or operations first.
>
> The output of functions is called the **returned value**.
Often, we will use multiple functions, in a nested way, or use parenthesis to change the order of operation. Being able to read nested operations, nested functions, and parenthesis is very important. Think about what the Python is going to do step-by--step in the line 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 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:


``` python
(len("hello") + 4) * 2
max(len("hello"), 4)
```

```
## 18
## 5
```

``` python
(len("pumpkin") - 8) * 2
```

If we don't know how to use a function, such as `pow()` we can ask for help:
```
## -2
```

If we don't know how to use a function, such as `pow()`, we can ask for help:

```
?pow
Expand Down Expand Up @@ -300,11 +310,19 @@ And there is an operational equivalent:
## 8
```

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. Here are some varieties of functions to stretch your horizons.

| Function call | What it takes in | What it does | Returns |
|---------------|---------------|----------------------------|---------------|
| `pow(a, b)` | integer `a`, integer `b` | Raises `a` to the `b`th power. | Integer |
| `print(x)` | any data type `x` | Prints out the value of `x` to the console. | None |
| `datetime.now()` | Nothing | Gets the current time. | String |

## Tips on writing your first code

`Computer = powerful + stupid`

Even the smallest spelling and formatting changes will cause unexpected output and errors!
Computers are excellent at doing something specific over and over again, but is extremely rigid and lack flexibility. Here are some tips that is helpful for beginners:

- Write incrementally, test often

Expand All @@ -315,3 +333,7 @@ Even the smallest spelling and formatting changes will cause unexpected output a
- Ask for help!

To get more familiar with the errors Python gives you, take a look at this [summary of Python error messages](https://betterstack.com/community/guides/scaling-python/python-errors/).

## Exercises

Exercise for week 1 can be found [here](https://colab.research.google.com/drive/1AqVvktGz3LStUyu6dLJFsU2KoqNxgagT?usp=sharing).
Loading

0 comments on commit 370115f

Please sign in to comment.