Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions book/Week1/input_to_output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# From input to output
So now we now what this does:
```Python
print("Hello World")
```
Printing "Hello World" is the start of almost every programmer's journey. It is a staple in the programming community. It is also, **very boring**.

In essence, this program does nothing. It runs, outputs something, and then exits. If you want to do something interesting, we have to give a program something to work with. We have to give it some **input**.

## What is input
Input is the stuff you want your program to react to, to do something with. On your phone you provide input to an app by clicking on a button, writing some text using the keyboard. Even scrolling down a screan is input.

In **Python** we mostly work with data input:
- Text that was put in by the user
- A file that has a million different numbers
- An image of your favourite teacher

A typical program takes this input, does what you want, and then returns the output.

## Variables
The whole point of input, is that it may be different every time you run your program. We need a place to store it so we can refer to it at a later time. This is what **variables** are for.

**Variables** are named datapoints that may be different every time. In Python you can create, or **assign**, a variable using the `=` sign, like so:

```Python
hello = "Hello World"
print(hello)
```
This code has created a **variable** called `hello` and assigned the value `"Hello World"` to it. Afterwards I can use that **variable** to return "Hello World" using `print()`.

## Simple input
Now that we know how to store input, we can ask for input in our program. Instead of the boring "Hello World", we can now create a program that says Hello, followed by your name.

```Python
name = input("What is your name? ")
print("Hello")
print(name)
```
`input()` asks the user to put in their name using their keyboard, and then stores the answer in the **variable** called `name`. After that we can return "Hello" and their name back to the user!
51 changes: 51 additions & 0 deletions book/Week1/what_is_python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# What does Python do
In the beginning, computers were programmed manually. If a programmer wanted to automate something using a computer, they had to put all kinds of switches in the right order for the program to run and work.

Luckily, we live in a day and age where everything is now digital.

## Machine code and compiled languages
Computers only understand specific instructions. *Move this data here* or *Add this value and this value together*. The programmers that used to program in instructions like those were practically wizards. They would be able to deduce what the following program does just by looking at it:

```nasm
section .data
message db "Hello, World!", 10
length equ $ - message

section .text
global _start

_start:
; write(stdout, message, length)
mov rax, 1 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
mov rsi, message ; pointer to message
mov rdx, length ; message length
syscall

; exit(0)
mov rax, 60 ; syscall: exit
xor rdi, rdi ; exit code 0
syscall
```

## How Python is different
Python is build on layers and layers of other programming code that takes care of all the details and boring stuff. Because of that, the code that was shown above in Assembly can be written in Python like this:

```Python
print("Hello World")
```

Only one line of code is enough. This will show, or **return**, the phrase "Hello World" to the person that runs this bit of code.

That is in essence how Python works. You give it a line of code, Python:
- **interprets** the code
- **returns** the outcome
- **moves** to the next line of code

Thus, when you give it two lines of code, it will run the first, and then the second.

```Python
print("one")
print("two")
```
Will return "one", followed by "two".
25 changes: 25 additions & 0 deletions book/Week1/why_and_how.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Why do we use programming code

We use computers every day. We use them to text our friends, scroll on Insta, find out where the nearest pizza place is. Computers are fast, powerful, and only getting faster and more powerful every year. Problem is: computers are also very, **very**, dumb.

You need to tell a computer *exactly* what to do, or:
- It will not do it, or, maybe even worse,
- Do something unexpected.

But how do you tell a computer what to do in a way that can only be interpreted in **one single way**?

## Programming Code

Everything you do on a computer, be it your laptop, your phone, your smartwatch, is only made possible through programming code.
- You hit a like button?
- Code is *executed* to make the like counter go up by one
- You ignore your mum calling you?
- Code is *executed* so she gets your voicemail instead
- You are reading this very sentence?
- Code was *executed* to get it from my keyboard to your eyes

My point is, that programming code is everywhere, programmers and designers have just gotten much better at hiding it exists.

If you want to get the most out of your computer, if you want to make it do stuff nobody has thought of before, want to automate some process, or are simply too lazy to do stuff by hand:

**Learning to code will open those doors for you**.
4 changes: 4 additions & 0 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parts:
chapters:
- file: Week1/Folders.md
- file: Week1/installation.md
- file: Week1/why_and_how.md
- file: Week1/what_is_python.md
- file: Week1/input_output.md

# - file: exercise_notebooks/exercise_notebook_week_1.ipynb

# - caption: Files and folders
Expand Down
Loading