CSCI Fall 2018 Midterm Flashcards
conditional execution
instruction check for certain conditions, and run their accompanying code
repetition
instruction to perform some action repeatedly, usually with some variation
Python interpreter
program that reads and executes python code
> > >
prompt. telling you that interpreter is ready for you to enter code
*
multiply
**
62 = 36
33=27
exponent
ctrl + z
zombies the program. stops it in its track
kill %n
kills the nth job–use carefully
value
one of the basic things a program works with, like a letter or a number. Some
values we have seen so far are 2, 42.0, and ‘Hello, World!’.
type
integers, floating-point numbers, strings
type()
gives you what type of value is inside the parentheses
prompt
Characters displayed by the interpreter to indicate that it is ready to take input
from the user.
interpreter
A program that reads another program and executes it
program
A set of instructions that specifies a computation
Operator
A special symbol that represents a simple computation like addition, multiplication,
or string concatenation.
int
type
integer
whole number
float
type
numbers with fractional parts
string
sequence of charachters
syntax
rules that govern structure of program
assignment statement
creates a new variable and gives it a value:
»> message = ‘And now for something completely different’
»> n = 17
»> pi = 3.141592653589793
Python key words
False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise
string concatenation
The + operator performs string concatenation, which means it joins the strings by linking them end-to-end. For example: >>> first = 'throat' >>> second = 'warbler' >>> first + second throatwarbler
syntax error
“Syntax” refers to the structure of a program and the rules about that structure.
For example, parentheses have to come in matching pairs, so (1 + 2) is legal,
but 8) is a syntax error.
semantic error
The third type of error is “semantic”, which means related to meaning.
If there is a semantic error in your program, it will run without generating error
messages, but it will not do the right thing. It will do something else. Specifically, it
will do what you told it to do.
runtime error
The second type of error is a runtime error, so called because the error does
not appear until after the program has started running. These errors are also called
exceptions because they usually indicate that something exceptional (and bad) has
happened.
variable
name that refers to a value
assignment
statement that assigns to a variable
keyword
A reserved word that is used to parse a program; you cannot use keywords like
if, def, and while as variable names.
statement
A section of code that represents a command or action. So far, the statements
we have seen are assignments and print statements.
concatenate
: To join two operands end-to-end.
argument
expression in parenthesis of a function call function(argument) print('hello world')
function
It is common to say that a function “takes” an argument and “returns” a result. The result
is also called the return value.
module
a file that contains a collection of related functions.
import some module
to call on a function in amodule
To access
one of the functions, you have to specify the name of the module and the name of the
function, separated by a dot (also known as a period). This format is called dot notation.
»> ratio = signal_power / noise_power
»> decibels = 10 * math.log10(ratio)
»> radians = 0.7
»> height = math.sin(radians)
The first example uses math.log10 to compute a signal-to-noise ratio in decibels (assuming
that signal_power and noise_power are defined). The math module also provides log,
which computes logarithms base e.
function definition
specifies the name of a new function and the sequence of statements that run when the function is called. Here is an example: def print_lyrics(): print("I'm a lumberjack, and I'm okay.") print("I sleep all night and I work all day.")
paramaters
parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method’s parameters. Parameter is variable in the declaration of function.
equivalent to argument
local variables
When you create a variable inside a function, it is local, which means that it only exists
inside the function.