Python Programming · Week 1

Orientation and Setup:
Your First Program

Hyeongmin Lee · SeoulTech, Dept. of Electronic Engineering

Hyeongmin Lee

About me

Hyeongmin Lee

Assistant Professor · Dept. of Electronic Engineering · ViViD Lab

computer vision video AI world models

I teach computers to see, and to imagine.

Orientation

This course

no experience needed

we start from zero

hands-on

you write code every week

your first language

the ideas transfer to every language

Orientation

The weekly cycle

1

theory video

the idea

2

practice video

code along

3

exercise

try it yourself

4

in-person class

solutions · Q&A

every week · everything on e-Class

Exercise solutions appear only in class.

Orientation

Grading

10%

attendance

30%

midterm

30%

final

30%

homework

homework = light weekly exercises · the easiest points in this course

Orientation

Exams

written on paper, code by hand

write code · find the error · predict the output

no computer no internet no AI

The exercises are the exam prep.

Orientation

Attendance rules

  • · attendance is checked, every class in the classroom · videos on e-Class
  • · no points lost missing a class or two will not lower your score
  • · one hard rule: attend at least 2/3 below 2/3 → F, by university rules · 3 lates = 1 absence
Orientation

Exercises and AI

Tony Stark taking the suit back from Peter Parker

Spider-Man: Homecoming (2017)

“If you're nothing without the suit,
then you shouldn't have it.”
homework: AI allowed exams: no AI, handwritten
Orientation

Using AI well

  • 1 try it without AI first ten minutes of struggle beat one hour of copying
  • 2 ask why, not answers “explain this error” beats “solve this for me”
  • 3 then write your own code read, understand, close the window, type it yourself

Train without the suit.

Orientation

Language

lectures in English

code · error messages · documentation: all in English anyway

Korean recap at the end of every class

so nobody gets lost

Orientation

Getting help

office

Changhak Hall 334-1

email

hyeongmin.lee@seoultech.ac.kr

topics

course · career · anything

Email me first to set a time. Do not sit alone with a problem for a week.

A question

import turtle

t = turtle.Turtle()
t.speed(0)

for i in range(300):
    t.forward(i * 0.5)
    t.left(91)

What do these six lines do?

Spiral pattern drawn by the six-line turtle program

six lines.

In a few weeks, you write this yourself.

The core idea

a program =
a list of instructions

nothing more · nothing less

The core idea

Giving directions

  1. 1 Come out of the station, exit 3
  2. 2 Go straight for two blocks
  3. 3 Turn left at the bank
  4. 4 The third building on the right

one wrong instruction your friend is lost

The golden rule

what you wrote,
not what you meant

the computer never guesses

The core idea

a computer =
a very fast calculator

add subtract multiply divide compare repeat

no meanings · no intentions · only operations

The core idea

Source code and the interpreter

source code

hello.py

a plain text file · you write it

interpreter

Python

a program that reads your text, line by line

result

the computer acts

text on screen · a drawing · a file

“Python” names both the language and the interpreter.

The core idea

Execution order

print("Good morning")
print("Good afternoon")
print("Good evening")

Good morning

Good afternoon

Good evening

Top to bottom. One line at a time.

Why Python

Python and C

The same task, twice.

C

#include <stdio.h>

int main(void) {
    printf("Hello, world!\n");
    return 0;
}

Python

print("Hello, world!")
readable runs instantly batteries included

You do not need to read the C. That is the point.

Why Python

What Python can do

data

import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 9, 16], "o-")
plt.show()
Default matplotlib plot

images

from skimage import data, filters

edges = filters.sobel(data.astronaut()[..., 0])
Astronaut photo and its edge map

automation

from pathlib import Path

for f in Path("photos").glob("*.jpg"):
    f.rename("trip_" + f.name)

IMG_2041.jpg trip_IMG_2041.jpg

IMG_2042.jpg trip_IMG_2042.jpg

… × 1,000

AI

from transformers import pipeline

clf = pipeline("sentiment-analysis")
clf("I love this course!")

[{'label': 'POSITIVE',
  'score': 0.9998}]

AI speaks Python.

Before we set up

The three tools

editor

write

where you type the text · VS Code

interpreter

run

reads your file, makes the computer act · Python

terminal

command

where you talk to the computer directly

Lost later in the course? Come back to this picture.

Next steps

Next: the practice video.

install Python + VS Code run your first program exercise 1

Watch it with your hands on the keyboard.

See you in class.

← All decks
01 / 00
Scroll · ↓ · Space