diff --git a/docs/day1.md b/docs/day1.md new file mode 100644 index 0000000..a5a915c --- /dev/null +++ b/docs/day1.md @@ -0,0 +1,143 @@ +# Day 1 + +Before we can dive into our web project we have to cover some Python basics. Let's talk about writing a python program. + +## The Interactive Python Prompt + +1. Make sure you have a (venv) to the left of your terminal cursor. Type `python` and press enter. + + ![python_prompt](img/day1/python_prompt.gif) + +1. Type `1+1` and press enter. You should see `2` returned. As long as you see the `>>>` to the left of your cursor you can type any python code you want and press enter to execute it. + + **NOTE**: This is not a terminal! You cannot run your django server from here. Before you can do things in the terminal you must exit by typing `exit()`! + +1. Type `x=1` and press enter. Nothing should return. + +1. Type `x` and press enter. You should see `1` return. We've give `x` the value of `1` + +1. Type `x+1` and press enter. You should see `2` returned just like `1+1` above. + +1. Type `x=3` and press enter. Nothing should return. + +1. Type `x` and press enter. You should see `3` return. Variables in Python can be reassigned to anything else. + +1. Type `x="hello"` and press enter. Nothing should return. + +1. Type `x` and press etner. You should see `hello` printed to the screen. Variables in python do not have a "type" - they can be integers, strings, floats, etc and can switch between them at will. + +1. Type `my_name = "\"` and press enter. Nothing should return + +1. Type `my_name` and press enter. You should see your name printed to your terminal. `my_name` is a much better variable name than `x`. It describes the thing it stores. Please use variable names that are descriptive. + +1. Type `my_coordinates = (1,2)` and press enter. Nothing should return. + +1. Type `my_coordinates` and press enter. `(1,2)` should return. This is called a `tuple`. It's useful for storing multiple points of data. + +1. Type `address = (123, "lane ave", "Columbus", "OH", 43212)` and press enter. Nothing should return + +1. Type `address` and press enter. You should see the address print to the terminal. Tuples can hold multiple types of data - 123 is a number and "lane ave" is a string. + +1. Type `len(address)` and press enter. You should see `5` printed to the terminal. There are 5 "things" in the tuple: + + `123 ` (1) + + `"lane ave"` (2) + + `"Columbus"` (3) + + `"OH"` (4) + + `43212` (5) + +1. Type `address[0]` and press enter. You should see `123` printed to the terminal. You just accessed the first item in the tuple. Tuples and other collections start at 0 and count up. + +1. Type `address[1]` and press enter. You should see `"lane ave"` print to the terminal. You just accessed the second item in the tuple + +1. Type `vocabulary = {"apple": "the usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family.", "banana": "a tropical plant of the genus Musa, certain species of which are cultivated for their nutritious fruit."}` and press enter. Nothing should return. + +1. Type `vocabulary` and press enter. {"apple": ...} should print to the terminal. This is called a dictionary. + +2. Type `vocabulary["apple"]` and press enter. `'the usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family.'` should print to the terminal. You just access the definition of apple. Much like tuples can be accessed with `address[0]` or `address[1]`, dictionary values can be accessed by supplying the keyword, or key for short. + +1. Type `exit()` and press enter. You should no longer see `>>>` to the left of the cursor. + +## A Python Program + +1. Create a new file called `myprogram.py` by clicking the "add file" icon in the top left of VSCode. + + ![add_file](img/day1/add_file.png) + + ![name_file](img/day1/name_file.png) + + ![open_file](img/day1/open_file.png) + + +1. In this file type `print('hello, world!')` and save with ctrl+S + + ![type_hw](img/day1/type_hw.png) + +1. In the terminal type `python my_program.py` and press enter. You should see `hello, world!` printed to the terminal. + + ![run_hw](img/day1/run_hw.gif) + +1. Congratulations! You ran your first python file. Just like the python command prompt above, running `python ` on a file with python code in it will execute that python code. Now we can run multiple lines of python at once! + +1. Below `print('hello, world!')` type `print('goodbye!)` + + ![print_goodbye](img/day1/print_goodbye.png) + +1. Below `print('goodbye')` type + + ```python + x = 1 + y = 2 + print(x + y) + my_name = "" + print(my_name) + ``` + + ![type_more_code](img/day1/type_more_code.png) + +1. In your terminal type `python myprogram.py` and press enter. You should see + + ```bash + hello, world! + goodbye! + 3 + Reese + ``` + + printed to the terminal + +1. This is out of order. We want to print "goodbye" last. Let's fix that with functions. + +1. Above `print('hello, world!')` type `def print_hello():` + + ![def_ph](img/day1/def_ph.png) + +1. Indent `print('hello, world!')` by pressing tab + + ![indent_hw](img/day1/indent_hw.png) + +1. Give 'goodbye' the same treatment. This time type `def print_goodbye():` + + ![print_gb](img/day1/print_gb.png) + +1. Finally add `def middle_stuff():` above the remaining code + + ![middle_stuff](img/day1/middle_stuff.png) + +1. Now type `python my_program.py` in the terminal and press enter. Nothing will return. + +1. We've given our snippets of code "names" by adding a "def" above them. These are called functions. We can call them in any order we want. Let's call them in the correct order by using their names. Add the following to the bottom of my_program.py + + ```python + print_hello() + middle_stuff() + print_goodbye() + ``` + + ![functions_in_order](img/day1/functions_in_order.png) + +1. Type `python my_program.py` in the terminal and press enter. Now everything prints in order! \ No newline at end of file diff --git a/docs/img/day1/add_file.png b/docs/img/day1/add_file.png new file mode 100644 index 0000000..7830d81 Binary files /dev/null and b/docs/img/day1/add_file.png differ diff --git a/docs/img/day1/def_ph.png b/docs/img/day1/def_ph.png new file mode 100644 index 0000000..de2c175 Binary files /dev/null and b/docs/img/day1/def_ph.png differ diff --git a/docs/img/day1/functions_in_order.png b/docs/img/day1/functions_in_order.png new file mode 100644 index 0000000..ae24656 Binary files /dev/null and b/docs/img/day1/functions_in_order.png differ diff --git a/docs/img/day1/indent_hw.png b/docs/img/day1/indent_hw.png new file mode 100644 index 0000000..77c95a9 Binary files /dev/null and b/docs/img/day1/indent_hw.png differ diff --git a/docs/img/day1/middle_stuff.png b/docs/img/day1/middle_stuff.png new file mode 100644 index 0000000..fd69c15 Binary files /dev/null and b/docs/img/day1/middle_stuff.png differ diff --git a/docs/img/day1/name_file.png b/docs/img/day1/name_file.png new file mode 100644 index 0000000..bb79522 Binary files /dev/null and b/docs/img/day1/name_file.png differ diff --git a/docs/img/day1/open_file.png b/docs/img/day1/open_file.png new file mode 100644 index 0000000..4f46907 Binary files /dev/null and b/docs/img/day1/open_file.png differ diff --git a/docs/img/day1/print_gb.png b/docs/img/day1/print_gb.png new file mode 100644 index 0000000..ba06ea6 Binary files /dev/null and b/docs/img/day1/print_gb.png differ diff --git a/docs/img/day1/print_goodbye.png b/docs/img/day1/print_goodbye.png new file mode 100644 index 0000000..3db9bfd Binary files /dev/null and b/docs/img/day1/print_goodbye.png differ diff --git a/docs/img/day1/python_prompt.gif b/docs/img/day1/python_prompt.gif new file mode 100644 index 0000000..866f942 Binary files /dev/null and b/docs/img/day1/python_prompt.gif differ diff --git a/docs/img/day1/run_hw.gif b/docs/img/day1/run_hw.gif new file mode 100644 index 0000000..3ebdbd1 Binary files /dev/null and b/docs/img/day1/run_hw.gif differ diff --git a/docs/img/day1/type_hw.png b/docs/img/day1/type_hw.png new file mode 100644 index 0000000..8e3bc2d Binary files /dev/null and b/docs/img/day1/type_hw.png differ diff --git a/docs/img/day1/type_more_code.png b/docs/img/day1/type_more_code.png new file mode 100644 index 0000000..f7ba910 Binary files /dev/null and b/docs/img/day1/type_more_code.png differ