배울 내용
- Course Info
- What is computation?
- python basics
- mathmatical operations
- python variables and types
0. Course info
Topics
- Learning how to program
- represent knowlege with data structures
- iteration and recursion as computational metaphors
- How do you write good code
- abstraction of procedures and data types
- organize and modularize systems using object classes and methods
- Computer science
- different classes of algorithms, searching and sorting
- complexity of algorithms
1. What is computation?
What does a computer do?
-
Calculation
: built-in
: ones that you define
-
remembers results
-
only know what you tell them
Types of knowlege
- Declarative knowledge : fact
- Imperative knowledge : recipe or "how-to"
What is a recipe?
- Sequence of simple steps
- Flow of control
- A means of determining when to stop
=> 1 + 2 + 3 = Algorithm
Stored Program Computer
- Sequence of instructions stroed inside computer
- Special program (interpreter) executes each instruction in order
Basic Primitives
- In computing, language primitives are the simplest elements available in a programming language. A primitive is the smallest 'unit of processing' available to a programmer of a given machine, or can be an atomic element of an expression in a language. (From Wiki)
- Turing showed that you can compute anything using 6 primitives (move left/right, read, write, scan, do nothing)
- anything computable in one language is computable in any other programming language
Aspects of languages
-
Primitive constructs
-
Syntax
: Symbol 이 배치되는 구조나 형식
-
(Static) Semantics
: Syntatically valid strings that have meaning
: Syntax의 틀에 따라 작성된 언어를 이해하는 방법이나, 의미
(https://jidoc.tistory.com/895)
: 예를 들자면
3.2 * 5 // syntatically valid
3 + "hi" // static semantic error
-
Programming languages have only one meaning but may not be what programmer intended
Where things go wrong
-
Syntatic errors
: common and easily caught
-
static semantic errors
: cause unpredictable behavior
-
no semantic errors but different meaning than what programmer intended
: program crashes, stops running
: program runs forever
: program gives an answer but different than expected
2. Python Basics
Objects
- programs manipulate data objects (everything is object)
- objects have type
- scalar (cannot be subdivided) / non-scalar (have internal structure)
Scalar Objects
- int
- float
- bool (True / False)
- NoneType : special and has one value, None
- Can you type() to see teh type of an object
Type conversion
- can convert object of one type to another
- float(3) : integer 3 to float 3.0
- int(3.9) truncates (끝을 자른다) float 3.9 to integer 3
3. Mathmatical Operations
Operations on ints and floats
-
i + j / i - j / i * j
: if both are ints, result is int
: if either or both are floats, result is float
-
i / j
: result is float
-
i % j
: remainder
-
i ** j
: i to the power of j (i^j)
4. Python variables and types
Binding Variables and Values
-
Equal sign is an assignment
pi = 3.14159
: pi is variable, 3.14159 is value
pi_approx = 22/7
-
Value stored in computer memory
-
Assignment binds name to value
Changing Bindings
- can re-bind variable names using new assignment stastements
pi = 3.14
radius = 2.2
area = pi * (radius**2)
radius = radius + 1
# value of area is not changed
Abstracting Expressions
- Why give names to values of expression?
: to reuse names instead of values
: easier to change code later
번외 : Programming vs Math
- Math : solve for x
- Programming : you need to tell the computer exactly how to solve for problem