Week 1: Python Basics Flashcards
WHAT DOES A COMPUTER DO
Fundamentally:
◦performs calculations a billion calculations per second!
two operations in same time light travels 1 foot
◦remember results
100s of gigabytes of storage!
typical machine could hold 1.5M books of standard size
What kinds of calculations?
◦built-into the language
◦ones that you define as the programmer
TYPES OF KNOWLEDGE / Declarative knowledge
Is statements of fact.
◦there is candy taped to the underside of one chair
TYPES OF KNOWLEDGE / Imperative knowledge
Is a recipe or “how-to”knowledge:
It uses a sequence of steps to find a solution:
1) face the students at the front of the room
2) count up 3 rows
3) start from the middle section’s left side
4) count to the right 1 chair
5) reach under chair and find it
WHAT IS A RECIPE?
1) sequence of simple steps
2) flow of controlprocess that specifies when each step is executed
3) a means of determining when to stop
Steps 1+2+3 = an algorithm!
How to capture a recipe in a mechanical process?
Fixed program computer:
◦calculator
◦Alan Turing’s Bombe
Stored program computer:
◦machine stores and executes instructions
What is a Stored program computer?
Sequence of instructions stored inside computer
◦built from predefined set of primitive instructions:
1) arithmetic and logic
2) simple tests
3) moving data
Special program (interpreter) executes each instruction in order:
◦use tests to change flow of control through sequence
◦stop when done
In computability theory what is the Turing completeness?
Turing showed you can compute anything using 6 primitives
Anything computable in one language is computable in any other programming language
What is an Expression?
Expressions are complex but legal combinations of primitives in a programming language
Syntax
Particular way that you need to write and structure your code in a language so that the computer understands.
English:
“cat dog boy” not syntactically valid
“cat hugs boy” syntactically valid
Programming language: “hi”5 not syntactically valid
3.2*5 syntactically valid
Static semantics
Static semantics is which syntactically valid strings have meaning
◦English: “I are hungry”
syntactically valid but static semantic error
◦programming language:
3.2*5 syntactically valid
3+”hi” static semantic error
Semantics
Semantics is the meaning associated with a syntactically correct string of symbols with no static semantic errors.
English: can have many meanings_
◦“Flying planes can be dangerous”
◦“This reading lamp hasn’t uttered a word since I bought it?”
◦programming languages: have only one meaning but may not be what programmer intended
WHERE THINGS GO WRONG
syntactic errors:
◦common and easily caught
static semantic errors:
◦some languages check for these before running program
◦can 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
What is a program?
A program is a sequence of definitions and commands
◦definitions evaluated
◦commands executed by Python interpreter in a shell
What is a command?
Commands (statements) instruct interpreter to do something
Can be typed directly in a shell or stored in a file that is read into the shell and evaluated
What are the characteristics a an object?
Programs manipulate data objects
Objects have a type that defines the kinds of things programs can do to them
objects are
◦scalar (cannot be subdivided)
◦non-scalar (have internal structure that can be accessed)