Top Banner
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
60

Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

Jun 05, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 2: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 3: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 4: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 5: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 6: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 7: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 8: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 9: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 10: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 11: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 12: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 13: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 14: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 15: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 16: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 17: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 18: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 19: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 20: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 21: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 22: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 23: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 24: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 25: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 26: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 27: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 28: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 29: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

How do they work?

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

Page 30: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

How do they work?

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

Page 31: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 32: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 33: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 34: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 35: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 36: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 37: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 38: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 39: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 40: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 41: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 42: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 43: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 44: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 45: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 46: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 47: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 48: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 49: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 50: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 51: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 52: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 53: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 54: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 55: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 56: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 57: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 58: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 59: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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

Page 60: Iskills: programming in Python from scratch!...Oct 28, 2018  · Iskills: programming in Python from scratch! Louis de Thanho er October 28, 2018 Louis de Thanho er Iskills: programming

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