Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from...

Preview:

Citation preview

Iskills: programming in Python from scratch!

Louis de Thanhoffer

October 28, 2018

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 1 / 25

What are we doing today?

Giving you a good idea of what programming is and how it works:

1 some of the history

2 what a programming language is (and why we need it)

3 the fundamentals of a programming language (in Python)

4 trying things yourself: playing tic-tac-toe

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 2 / 25

What are we doing today?

Giving you a good idea of what programming is and how it works:

1 some of the history

2 what a programming language is (and why we need it)

3 the fundamentals of a programming language (in Python)

4 trying things yourself: playing tic-tac-toe

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 2 / 25

What are we doing today?

Giving you a good idea of what programming is and how it works:

1 some of the history

2 what a programming language is (and why we need it)

3 the fundamentals of a programming language (in Python)

4 trying things yourself: playing tic-tac-toe

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 2 / 25

What are we doing today?

Giving you a good idea of what programming is and how it works:

1 some of the history

2 what a programming language is (and why we need it)

3 the fundamentals of a programming language (in Python)

4 trying things yourself: playing tic-tac-toe

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 2 / 25

What are we doing today?

Giving you a good idea of what programming is and how it works:

1 some of the history

2 what a programming language is (and why we need it)

3 the fundamentals of a programming language (in Python)

4 trying things yourself: playing tic-tac-toe

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 2 / 25

the history of programming

Charles Babbage (1837) : produces the first machine to mechanicallydo math using rotors. It already has ”logic” and memory”

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 3 / 25

the history of programming

Charles Babbage (1837) : produces the first machine to mechanicallydo math using rotors. It already has ”logic” and memory”

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 3 / 25

the history of programming

Ada Lovelace (nee Byron): works with Babbage and produces thefirst ”algorithm”

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 4 / 25

the history of programming

Ada Lovelace (nee Byron): works with Babbage and produces thefirst ”algorithm”

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 4 / 25

the history of programming

Alan Turing (’39): invents computing and cracks Enigma (essentiallywinning WW2)

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 5 / 25

the history of programming

Alan Turing (’39): invents computing and cracks Enigma (essentiallywinning WW2)

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 5 / 25

the history of programming

Konrad Zuse (’41): builds the first digital computer during WW2(inventor of the computer)

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 6 / 25

the history of programming

Konrad Zuse (’41): builds the first digital computer during WW2(inventor of the computer)

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 6 / 25

the history of programming

John Backus: invents the first (real) programming language: Fortran

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 7 / 25

the history of programming

John Backus: invents the first (real) programming language: Fortran

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 7 / 25

Bill Gates makes the first basic interpreter on the altair crating thefirst software company (72)

Jobs works with gates on implementing basic in the Apple 2

Gates clones GUI on Windows and so it begins...

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 8 / 25

Bill Gates makes the first basic interpreter on the altair crating thefirst software company (72)

Jobs works with gates on implementing basic in the Apple 2

Gates clones GUI on Windows and so it begins...

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 8 / 25

Bill Gates makes the first basic interpreter on the altair crating thefirst software company (72)

Jobs works with gates on implementing basic in the Apple 2

Gates clones GUI on Windows and so it begins...

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 8 / 25

Bill Gates makes the first basic interpreter on the altair crating thefirst software company (72)

Jobs works with gates on implementing basic in the Apple 2

Gates clones GUI on Windows and so it begins...

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 8 / 25

Guido Van Rossum invents Python (named after Monty Python) tobe a very easy to use and flexible language

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 9 / 25

Guido Van Rossum invents Python (named after Monty Python) tobe a very easy to use and flexible language

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 9 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

Why programming?

Think about calculators....

What if you had to understand exactly how every part of a calculatorworks in order to use it?

That would be impossible!

Enter programming languages..

you can now easily use a calculator

and pick up any one from your favorite Dollarama

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 10 / 25

How do they work?

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 11 / 25

How do they work?

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 11 / 25

Machine language

Tell the computer exactly what to do with each step of the program (interms of bits)

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 12 / 25

Assembly language

Use a set of easier commands to implement machine language

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 13 / 25

higher level language

Build a whole language that in turn interprets the set of instructions(compiles), translates into assembly and machine language

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 14 / 25

Python

Python is such an example and particularly good at its job:

...compare other languages:

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 15 / 25

Python

Python is such an example and particularly good at its job:

...compare other languages:

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 15 / 25

Python

Python is such an example and particularly good at its job:

...compare other languages:

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 15 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

What is a programming language?

vocabulary: data structures

primitive: integers, fl. point, yes/no, characters

composite: lists, dictionaries

math: arrays, matrices

grammar: functionalities

operations: +, -,*...

logical statements: if, while, for...

functions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 16 / 25

Let’s try it out:

We’ll open a programming language right from our browser:

go to Jupyter.org

try it in your browser

try JupyterLab

remove the Lorentz file (that’s just an example)

go to file/new/notebook and select the Python 3 kernel

print(”hello world”)

run the program

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 17 / 25

Let’s try it out:

We’ll open a programming language right from our browser:

go to Jupyter.org

try it in your browser

try JupyterLab

remove the Lorentz file (that’s just an example)

go to file/new/notebook and select the Python 3 kernel

print(”hello world”)

run the program

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 17 / 25

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 18 / 25

primitive data types

integers: 1,2, etc

floating point: pi

characters: ’hello’

find out the type using type()

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 19 / 25

primitive data types

integers: 1,2, etc

floating point: pi

characters: ’hello’

find out the type using type()

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 19 / 25

lists

a way to enumerate primitive data types: declare using [] notation

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 20 / 25

dictionaries

describe an assignment of keys to values

get the value of the key using []

d = ’hello’: 1, ’world’: 2

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 21 / 25

dictionaries

describe an assignment of keys to values

get the value of the key using []

d = ’hello’: 1, ’world’: 2

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 21 / 25

arrays

1 uses the library numpy, so import numpy as np

2 similar to lists but we can use math!

3 declare as np.array()

declare l = [1,2,3] as a list vs array...what happens?

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 22 / 25

arrays

1 uses the library numpy, so import numpy as np

2 similar to lists but we can use math!

3 declare as np.array()

declare l = [1,2,3] as a list vs array...what happens?

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 22 / 25

matrices

1 uses the library numpy again, so import numpy as np

2 like arrays in multiple dimensions

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 23 / 25

logical statements

a way to enumerate primitive data types: declare using [] notation

to find the first 10 squares: [x*x for x ≤ 10]

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 24 / 25

functions

input variables using brackets

declare as def

indent the body

output variables using return

build a function that returns the squares: def(x) return x ∗ x

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 25 / 25

functions

input variables using brackets

declare as def

indent the body

output variables using return

build a function that returns the squares: def(x) return x ∗ x

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 25 / 25

tic-tac-toe

Now let’s try and build tic-tac toe!

go to github.com/ldethanhoffer/tic-tac-toe

download tic-tac-toe

upload to jupyter

Louis de Thanhoffer Iskills: programming in Python from scratch! October 28, 2018 26 / 25

Recommended