Computer and Python Basics
- 82Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is computational thinking?
Using computation to help solve problems, rather than relying only on manual or mathematical methods.
Or swipe the card
82 cards
What is computational thinking?
Using computation to help solve problems, rather than relying only on manual or mathematical methods.
What are three key outcomes of learning programming?
Knowledge of computer science concepts, programming skill, and problem-solving skill.
How do programming skill and problem-solving skill differ?
Programming skill is writing code; problem-solving skill includes translating a problem into computer science concepts and then into a program.
Why does learning to program require hands-on practice?
Programming is a skill that develops through repeated practice; watching code being written does not by itself prepare you to write code.
How can computation help with a problem you already know how to solve mathematically?
You can apply computation to automate or assist with solving the problem, rather than solving it only by hand.
What does it mean for code to be modular?
Code is organized into separate, manageable parts rather than being left as one undifferentiated block.
What question does algorithmic complexity help answer?
Whether a program or algorithm is efficient, including how fast it runs and how much memory it uses.
What is declarative knowledge?
A statement of fact about what is true, rather than a recipe explaining how to do something.
What is imperative knowledge?
A recipe or set of instructions describing how to accomplish something.
Why is a declarative statement about a square root insufficient as instructions for a computer?
It describes a relationship between values but does not specify a procedure for finding the square root.
What is an algorithm?
A sequence of steps for solving a problem, with a defined flow of control and a way to stop.
What are three important features of an algorithm?
A sequence of steps, rules for how control proceeds (such as conditionals or repetition), and a stopping condition.
How does an iterative square-root procedure improve an initial guess?
It compares the guess squared with the target; if the guess is not close enough, it averages the current guess with the target divided by the guess, then repeats.
What does a stopping condition do in an algorithm?
It specifies when the procedure is close enough to its goal and should end, preventing it from continuing indefinitely.
How are ordinary recipes similar to algorithms?
Both can give ordered steps, include conditional or repeated actions, and specify when to stop.
What is a fixed-program computer?
A computer, such as a basic calculator, that performs operations selected through its controls but does not store a reusable sequence of instructions as a program.
What capability distinguished stored-program computers?
They could store instructions as data and use an interpreter to execute those instructions.
What basic kinds of operations could early stored-program computers perform?
Arithmetic, logical tests such as equality comparisons, and moving data between memory locations.
What are the roles of memory, the arithmetic logic unit, and the control unit in the simplified computer model?
Memory stores values; the arithmetic logic unit (ALU) performs arithmetic and comparisons; the control unit manages instruction execution, including the program counter.
In the example of adding two stored values, what does the ALU do and what does a later store instruction do?
The ALU adds the values and returns the result; a store instruction places that result in a specified memory location.
What does Alan Turing’s machine model illustrate about computation?
Computations can be built from a small set of simple operations, such as moving along a tape, reading or writing a value, erasing, and doing nothing.
What follows from the claim that any computation in one programming language can be expressed in another?
Different programming languages can express the same computable tasks, even if some languages require more primitive steps than others.
What is a programming-language primitive?
A basic building block of a language, such as a number, character sequence, or operation.
How do programming-language primitives relate to larger programs?
Primitives combine according to the language’s syntax to form expressions and more complex programs.
What is syntax in a programming language?
The rules specifying which arrangements of language elements are well-formed.
What is a static semantic rule?
A rule about whether a syntactically valid expression makes sense according to the language, such as whether an operation is allowed for its operands.
How do syntax and static semantics differ?
Syntax concerns the form of an expression; static semantics concerns whether that well-formed expression is meaningful under the language’s rules.
What is the semantics of a program?
The meaning or behavior of the program when it is executed.
Can a program have one execution meaning that differs from what its author intended?
Yes. A program’s instructions have a definite execution behavior, but that behavior may not match the author’s intention.
What are common examples of syntax errors?
Misspellings and indentation errors that make code violate the language’s syntax rules.
What is an example of a static semantic error in Python?
Using an operation that is not defined for the operand types, such as trying to add a string and a number.
What are possible symptoms of a program behaving differently from what its author intended?
It may crash, run without stopping, or terminate while producing an incorrect result.
What does the type of a Python object tell Python?
Which operations are allowed for that object.
What is an integer in Python?
A whole-number value, such as 5 or −100, with type
int.What is a float in Python?
A numeric value represented with type
float, such as 3.27 or 2.0.What values can a Python Boolean have?
TrueandFalse, with an uppercase first letter.What is the Python
NoneTypevalue?Noneis the single special value of typeNoneType.What are scalar objects in Python?
Primitive objects such as numbers and truth values that do not have the internal sequence structure of a collection.
What is a non-scalar object?
An object with internal structure, such as a list containing multiple numbers.
How can you inspect an object’s type in Python?
Use
type(object), such astype(7), which reportsint.How do Python’s
intandfloattypes differ for the values 2 and 2.0?2has typeint, while2.0has typefloat.Why does
type(true)raise an error in Python?Python is case-sensitive: the Boolean value must be written
True, nottrue.What does casting an integer to a float do?
It creates a float representation of the value; for example,
float(3)produces3.0without changing the original integer object.What does casting a float to an integer do?
It truncates the fractional part rather than rounding; for example,
int(5.9)produces5.What is an expression in Python?
A combination of values, operators, or other constructs that Python evaluates to a single value.
Does Python store an expression itself when it evaluates it?
No. It evaluates the expression to one value; the expression itself is not stored as the result.
Can an expression be used as an argument to a Python function or command?
Yes. Python evaluates the expression and passes its resulting value, as in
type(3 + 2).What does the expression
"Hi" * 5do in Python?It repeats the string five times, producing
HiHiHiHiHi.Why is
"Hi" + 5invalid in Python?The
+operation is not defined for combining a string and an integer.What is the result type of adding, subtracting, or multiplying two integers?
An integer.
What is the result type of adding, subtracting, or multiplying when at least one operand is a float?
A float.
What type does Python’s
/operator produce when dividing numbers?A float, including when the division has a whole-number result.
What does the
//operator do?It performs floor division, discarding the fractional part of the quotient; for example,
5 // 3is1.What does the
%operator do?It returns the remainder from division; for example,
5 % 3is2.What does the
**operator do in Python?It performs exponentiation; for example,
2 ** 3is8.How do the result types of
2 ** 3and2 ** 3.0differ?2 ** 3produces an integer; using a float operand, as in2 ** 3.0, produces a float.What is the order of arithmetic operator precedence in Python, from highest to lowest among these operators?
Exponentiation first; then multiplication, division, floor division, and remainder; then addition and subtraction.
How can parentheses affect the evaluation of an arithmetic expression?
They override the usual precedence by making the parenthesized part evaluate first.
What does
int(1 / 2)evaluate to, and why?It evaluates to
0: division first produces0.5, andinttruncates the fractional part.What does the
roundoperation do to a value such as7.9?It rounds the value to the nearest integer;
round(7.9)produces8.In Python, what does the equals sign in
name = valuemean?It is an assignment operator that binds the name to the value on the right; it does not assert mathematical equality.
What is a variable in the programming context described here?
A name bound to a value so that the program can refer to that value later.
How is a programming variable different from a variable in an algebraic equation?
A programming variable is bound to a particular value at a given point in execution; it is not a general unknown or a statement of equality.
How does Python evaluate an assignment such as
f = m * 9.98?It first evaluates the right-hand expression using the current value of
m, then binds the resulting value tof.What must appear on the left side of a basic Python assignment?
A single assignable variable name; an expression such as
x * ycannot be the assignment target.Why is
6 = xinvalid as a Python assignment?The left side must be a variable name, not a literal value.
Is
xy = 3 + 4a valid Python assignment? What value doesxyreceive?Yes. Python evaluates
3 + 4and binds the resulting value,7, toxy.What does rebinding a variable mean?
Changing which value a variable name refers to by assigning it a new value.
What happens when Python executes
radius = radius + 1?It reads the current value of
radius, adds one, and rebindsradiusto the result.Does changing a variable automatically update another variable whose value was calculated from it earlier?
No. A previously calculated variable keeps its value until the program explicitly assigns it a new one.
In what order does a basic program execute its lines when no control-flow constructs are present?
It executes them one after another, from top to bottom.
What is a temporary variable used for when swapping two values?
It preserves one value so that reassignment does not overwrite a value that is still needed.
How can you swap the values of
xandyusing a temporary variable?Use
temp = y, theny = x, thenx = temp.Why does the sequence
y = xfollowed byx = yfail to swap two variables?The first assignment overwrites the original value of
y, so both names end up bound to the original value ofx.Why use descriptive variable names instead of arbitrary single letters?
Descriptive names make code easier for the author and others to understand later.
What is a Python comment, and how is it marked?
A comment is explanatory text ignored as an instruction by the program; it begins with
#.What makes a code comment useful?
It explains the purpose or intent of a section of code, rather than merely restating what the code visibly does.
Why assign a repeated value, such as an approximation of pi, to a variable?
It avoids repeatedly copying the value and makes the program easier to read and maintain.
What is Python Tutor useful for?
It lets you step through a program line by line and inspect variable values, which helps with debugging.
What is the shell useful for when programming?
It is useful for quickly trying a command or checking an expression without writing and running a complete program.
What is one practical benefit of testing expressions or commands interactively?
You can check what they do and inspect their results before incorporating them into a larger program.
What is the difference between the program’s actual behavior and its intended behavior?
Actual behavior is what the executed instructions do; intended behavior is what the programmer wants them to do, and the two may differ.

Ask anything
We've read this whole study set, so questions about it get the best answers.