Python Programming: Chapters 1-4
input, process, output (IPO)
a common programming pattern; prompts for input, processes it, outputs a response
loop
a control construct for executing portions of a program multiple times
string
a data type for representing a sequence of characters (text)
algorithm
a detailed sequence of steps for carrying out some process; a recipe
program
a detailed set of instructions for a computer to carry out; composed of statements that are built from identifiers and expressions
list
a general Python data type for representing sequential collections; heterogeneous (capable of holding more than one data type at a time) and can grow or shrink as needed; items accessed through subscripting
definite loop statement
a kind of loop where the number of iterations is known at the time the loop begins executing; ex: for <var(can be i, etc.)> in <sequence(can be range or a list)>: <body>
counted loop
a loop written to iterate a specific number of times; created using the range(n) function
computer
a machine that stores and manipulates information under the control of a changeable program
data type
a particular way of representing data; determines what values it can have and what operations it supports
prompt
a printed message that signals to the user of a program that input is expected
machine code
a program in machine language
literal
a representation of a specific value; ex: 3 represents three (int literal), "Hello" (string literal)
statement
a single command in a programming language
simultaneous assignment statement
a statement that allows multiple variables to be assigned in a single step; ex: <var1>, <var2>, ... , <varN> = <expr1>, <expr2>, ... , <exprN>
function
a subprogram within a program; take parameters as input and return values; ex: int(x) or def sing(animal, sound):
loop index
a variable that is being used to control a loop; ex: in the statement for i in range(n), i is this
accumulator variable
a variable used to hold the result in the accumulator programming pattern
math library function: arccos x
acos(x)
numeric operators
addition (+), subtraction (-), multiplication (*), division (/), exponentiation (**), remainder (%), absolute value (abs(x))
name error
an exception that occurs when Python is asked to produce a value for a variable that has not been assigned a value
library
an external collection of useful functions or classes that can be imported and used in a program; ex: math and string modules
variable
an identifier that labels/stores a value for future reference; can be changed through assignment; ex: term1 = 1
flowcharts
graphical depiction of the flow of control in a program or algorithm
reserved words
identifiers that are part of the built-in syntax of a language; ex: and, def, for, print
data
information that is stored and manipulated by computer programs
byte code
intermediate form of computer language, high-level languages are sometimes compiled into this, which is then interpreted; ex: Python files with .pyc extension
math library function: ln x
log(x)
math library function: log10 x
log10(x)
built-in function: explicit type conversion
long(x), int(x), and float(x) functions
import statement
makes an external library module available for use within a program; ex: import <module_name> - to use say <module_name>.<function>(x)
invoke
making the use of a function; ex: sing("cat","meow")
chaotic
mathematical model where small changes in input lead to large changes in the results; many models of real-world phenomena exhibit this
control structures
programming language statement that controls the execution of other statements; ex: if, for
built-in function: range function
range(start, stop, step) *stops at stop-1
built-in function: round function
round(x), rounds to nearest whole number, returns a float
math library function: sin x
sin(x)
programming environment
special computer program that provides facilities to make programming easier; ex: Wingware
portability
the ability to run a program unmodified on various different systems
machine language
the low-level (binary) instructions that a given CPU can execute
semantics
the meaning of a construct
hardware
the physical components of a computing system
main memory (RAM)
the place where all data and program instructions that the CPU is currently working reside.
fetch-execute cycle
the process a computer carries out to execute a machine code program (fetch one line, execute, fetch second line, execute, etc.)
programming
the process of creating a computer program to solve some problem
assignment statement
the process of giving a value to a variable; ex: <variable> = <expr>
source code
the text of a program in a high-level language
iterate
to do multiple times; each execution of a loop body is called an iteration
execute
to run a program or segment of a program
intractable
too difficult to be solved in practice, usually because it would take too long
built-in function: type function
type(n); tells the data type of any value
bit
typical PCs today use 32 bits, so there are 2^32 possible values; integers between -2^31 and 2^31-1
operators
used to combine expressions into more complex expressions; ex: + *
pseudocode
writing down algorithms using precise natural language, instead of a computer language
parameters
special variables in a function that are initialized at the time of call with information passed from the caller; ex: range(start, stop, step)
math library function: tan x
tan(x)
binary
base two numbering system in which the only digits are 0 and 1
mixed-type expressions
Python automatically converts ints to floats and uses float operations to produce a float result
integer division
discards the remainder
comment
text placed in a program for the benefit of human readers; ignored by the computer; delineated by # or """ [text] """
central processing unit (CPU)
the "brain" of the computer where numeric and logical operations are carried out
syntax
the form of a language
integer (int) data type
whole numbers, positive or negative
input (numeric)
<var> = input(<prompt>) <var1>, <var2>, ... , <varN> = input(<prompt>)
body
generic term for a block of statements inside of a control structure such as a loop or decision
software development process
analyze the problem (studying the problem to be solved), determine specifications (what the program will do), create a design (algorithm in pseudocode), implement the design (translate design to programming language), test/debug the program (finding and fixing errors), maintain the program (keeping up to date)
script
another name for a program, usually a simple one in an interpreted language
module
any relatively independent part of a program, also a file containing code that can be imported and executed
math library function: arcsin x
asin(x)
math library function: arctan x
atan(x)
math library function: ⎡x⎤
ceil(x)
elements of a computer system
central processing unit (CPU), main memory (RAM), secondary memory (hard drive), and input and output devices
butterfly effect
classic example of a chaotic system in nature
accumulator pattern
common programming pattern in which a final answer is built a piece at a time in a loop; initialize accumulator variable, loop until final result is reached, update accumulator variable
compiler
complex program that translates a program written in a high-level language into the machine language that can be executed by a particular computer; translates all at once
interpreter
computer program that simulates the behavior of a computer that understands a high-level language; executes the lines of source one by one and carries out the operations (Python is an interpreted language)
software
computer programs
math library function: cos x
cos(x)
math library function: e
e
math library function: e^x
exp(x)
math library function: ⎣x⎦
floor(x)
identifiers
names that are given to program entities; begin with an underscore or letter which can be followed by a combination of letter, digit, or underscore characters; case-sensitive
programming languages
notation for writing computer programs; usually high-level languages like Python
meta-languages
notation used to describe the syntax of a computer language
floating point (float) data type
numbers that can have fractional parts; only stores approximations to real numbers
long integer
numeric data type that can hold large values; uses "L" suffix; ex: 5L *this happens automatically in modern Python
expressions
part of a program that produces data
math library function: π
pi
print statement
print <expr>, <expr>, ... <expr>, (commas signal a continuation of the print line)
garbage collection
process carried out by dynamic programming languages in which memory locations that contain values that are no longer in use are freed up so they can store new values
coding
process of turning an algorithm into a computer program