1. Home
  2. Explore
  3. Computer Science
  4. Computer and Python Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Computer and Python Basics

  • 58Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Algorithms and Computation

What distinguishes imperative knowledge from declarative knowledge in programming?

58 questions

  1. 1

    What distinguishes imperative knowledge from declarative knowledge in programming?

    1. A

      Imperative knowledge is stored in memory, while declarative knowledge is stored in files.

    2. B

      Imperative knowledge describes steps for doing something, while declarative knowledge states a fact.

    3. C

      Imperative knowledge describes only mathematical truths, while declarative knowledge describes only computer hardware.

    4. D

      Imperative knowledge states a fact, while declarative knowledge describes steps for doing something.

    Correct answer
    B

    Imperative knowledge describes steps for doing something, while declarative knowledge states a fact.

    Explanation

    Imperative knowledge is a recipe of steps to follow. A declarative statement gives information about what is true but does not necessarily tell a computer what actions to take.

  2. 2

    Why would the statement “the square root of a number is a value whose square equals that number” not be a sufficient instruction for a computer?

    1. A

      It gives the computer too many possible procedures to execute at once.

    2. B

      It describes a result that can only be found by storing every real number.

    3. C

      It states a relationship but does not specify a procedure for finding the value.

    4. D

      It uses a mathematical idea that computers are unable to represent.

    Correct answer
    C

    It states a relationship but does not specify a procedure for finding the value.

    Explanation

    A computer needs imperative instructions—a procedure describing how to find the square root—not only a statement that characterizes the answer.

  3. 3

    Which combination best describes the basic structure of an algorithm discussed in the lecture?

    1. A

      A set of data, a programming language, and a storage device.

    2. B

      A mathematical result, a variable name, and a printed message.

    3. C

      A computer, an interpreter, and a user interface.

    4. D

      A sequence of steps, a flow of control, and a way to stop.

    Correct answer
    D

    A sequence of steps, a flow of control, and a way to stop.

    Explanation

    The lecture describes algorithms as sequences of steps that can change their flow of control and include a stopping condition.

  4. 4

    In the square-root procedure, how is a new guess formed from the current guess and the target number?

    1. A

      By subtracting the current guess from the target and doubling the difference.

    2. B

      By averaging the current guess with the target divided by the current guess.

    3. C

      By multiplying the current guess by the target and taking the integer portion.

    4. D

      By averaging the target with the square of the current guess.

    Correct answer
    B

    By averaging the current guess with the target divided by the current guess.

    Explanation

    The procedure forms the next guess by averaging the current guess and the target divided by that guess.

  5. 5

    Why does an iterative algorithm need a stopping condition?

    1. A

      Without one, the procedure must return more than one answer.

    2. B

      Without one, the computer cannot evaluate arithmetic expressions.

    3. C

      Without one, the computer cannot store intermediate values.

    4. D

      Without one, the procedure might continue indefinitely.

    Correct answer
    D

    Without one, the procedure might continue indefinitely.

    Explanation

    A stopping condition specifies when the algorithm should finish rather than repeat its steps forever.

  6. 6

    What is the main goal of computational thinking as described in the lecture?

    1. A

      To memorize computer operations without analyzing problems.

    2. B

      To make every solution use the fewest possible lines of code.

    3. C

      To consider how computation can be applied to help solve problems.

    4. D

      To replace every mathematical method with a programming language.

    Correct answer
    C

    To consider how computation can be applied to help solve problems.

    Explanation

    Computational thinking involves asking how computation can be applied to solve a problem, rather than relying only on manual or mathematical approaches.

  7. 7

    Which statement best explains why programming skill requires practice?

    1. A

      Programming can only be practiced after all computer science concepts are mastered.

    2. B

      Programming is a skill that develops through repeated hands-on use.

    3. C

      Programming mainly depends on memorizing terminology before attempting problems.

    4. D

      Programming is learned automatically by watching code being written.

    Correct answer
    B

    Programming is a skill that develops through repeated hands-on use.

    Explanation

    The lecture compares programming to skills such as mathematics or reading: repeated practice helps make it second nature.

  8. 8

    What question is algorithmic complexity intended to help answer?

    1. A

      How efficiently a program uses time and memory.

    2. B

      Whether a program's comments accurately summarize each line.

    3. C

      Whether a program is written in a particular programming language.

    4. D

      Whether a program uses valid variable names.

    Correct answer
    A

    How efficiently a program uses time and memory.

    Explanation

    Algorithmic complexity concerns efficiency, including how fast a program runs and how much memory it uses.

  9. 9

    Why is a cooking recipe a useful analogy for an algorithm?

    1. A

      Both produce exactly the same result regardless of the ingredients or starting conditions.

    2. B

      Both require a computer to interpret their instructions before any action can occur.

    3. C

      Both consist only of facts describing the desired final result.

    4. D

      Both can specify ordered steps, conditional actions or repetition, and a way to finish.

    Correct answer
    D

    Both can specify ordered steps, conditional actions or repetition, and a way to finish.

    Explanation

    Recipes, like algorithms, can include sequences of steps, flow of control such as conditions or repetition, and a stopping point.

  10. 10

    What was a key limitation of fixed-program computers such as pocket calculators?

    1. A

      They could not store a sequence of operations for reuse with different inputs.

    2. B

      They could only store instructions as data for an interpreter.

    3. C

      They could not perform arithmetic operations such as addition or subtraction.

    4. D

      They could not display a result after performing an operation.

    Correct answer
    A

    They could not store a sequence of operations for reuse with different inputs.

    Explanation

    With a fixed-program device such as a pocket calculator, users had to enter the operations again for each input rather than store a reusable sequence of operations.

  11. 11

    What capability distinguished stored-program computers from fixed-program computers?

    1. A

      They could store instructions as data and use an interpreter to execute them.

    2. B

      They could store only the results of programs, not the programs themselves.

    3. C

      They could make decisions without being given rules or instructions.

    4. D

      They could perform arithmetic without using any instructions.

    Correct answer
    A

    They could store instructions as data and use an interpreter to execute them.

    Explanation

    Stored-program computers can store instructions as data, and an interpreter executes those instructions.

  12. 12

    Which set contains operations that the lecture identified as basic computer instructions?

    1. A

      Displaying images, connecting to networks, and playing sound.

    2. B

      Writing comments, naming variables, and formatting source code.

    3. C

      Arithmetic, logical tests, and moving data between memory locations.

    4. D

      Choosing goals, interpreting human intent, and creating new instructions.

    Correct answer
    C

    Arithmetic, logical tests, and moving data between memory locations.

    Explanation

    The described basic instructions included arithmetic, logical tests such as checking equality, and moving data between memory locations.

  13. 13

    In the simplified computer model, what is the role of the arithmetic logic unit (ALU)?

    1. A

      It stores the program's instructions and controls their order.

    2. B

      It interprets the programmer's intended meaning.

    3. C

      It performs operations such as arithmetic and comparisons.

    4. D

      It assigns descriptive names to values in memory.

    Correct answer
    C

    It performs operations such as arithmetic and comparisons.

    Explanation

    The ALU performs operations such as addition, subtraction, multiplication, and comparisons.

  14. 14

    In the simplified computer model, what is associated with the control unit and program counter?

    1. A

      Converting source code into comments for the programmer.

    2. B

      Storing all program data without tracking instructions.

    3. C

      Performing every arithmetic operation on stored values.

    4. D

      Controlling which instruction is to be executed next.

    Correct answer
    D

    Controlling which instruction is to be executed next.

    Explanation

    The control unit includes the program counter, which is associated with directing the program's instruction flow.

  15. 15

    Why does a program's instruction to add two values need a separate instruction to store the result?

    1. A

      The addition produces a result, but that result is not stored at a memory location unless instructed.

    2. B

      The ALU can add values only after they have already been printed.

    3. C

      The computer stores results only when the two input values are unequal.

    4. D

      The interpreter automatically discards every result that is not a comparison.

    Correct answer
    A

    The addition produces a result, but that result is not stored at a memory location unless instructed.

    Explanation

    In the example, the ALU computed the sum, and a following instruction told the computer where in memory to store it.

  16. 16

    Which sequence describes the comparison example in the lecture?

    1. A

      The computer compares two memory locations without retrieving their values, then changes both values.

    2. B

      The computer prints two values, stores the printed text, and then adds the values.

    3. C

      The computer moves both values to the program counter and prints the memory locations.

    4. D

      The computer retrieves two values, compares them, and then prints the comparison result.

    Correct answer
    D

    The computer retrieves two values, compares them, and then prints the comparison result.

    Explanation

    The example retrieves values from memory, has the ALU compare them, and then prints the resulting truth value.

  17. 17

    Which set lists the six basic tape-machine operations attributed to Alan Turing in the lecture?

    1. A

      Store, retrieve, rename, sort, display, and delete.

    2. B

      Open, close, save, load, copy, and paste.

    3. C

      Move left, move right, read, write, erase, and do nothing.

    4. D

      Add, subtract, multiply, divide, compare, and print.

    Correct answer
    C

    Move left, move right, read, write, erase, and do nothing.

    Explanation

    The lecture listed moving the tape left or right, reading a value, putting a value on the tape, erasing a value, and performing no operation.

  18. 18

    What conclusion did the lecture draw from the universality of basic computational primitives?

    1. A

      All programming languages have the same speed and memory requirements.

    2. B

      Every programming language uses the same syntax and variable names.

    3. C

      A program written in one language can run in another without translation.

    4. D

      Anything computable in one programming language can also be computed in another.

    Correct answer
    D

    Anything computable in one programming language can also be computed in another.

    Explanation

    The lecture's conclusion was that anything computable in one language is computable in any other programming language, even if the programs use different forms.

  19. 19

    In the analogy between English and programming languages, what role do primitives play?

    1. A

      They are complete programs that cannot be combined with other elements.

    2. B

      They are explanations written after a program has finished running.

    3. C

      They are basic building blocks that can be combined into more complex expressions or structures.

    4. D

      They are special rules that let computers infer a programmer's intent.

    Correct answer
    C

    They are basic building blocks that can be combined into more complex expressions or structures.

    Explanation

    The lecture compares programming primitives to characters or words in English: basic elements combine to form larger structures.

  20. 20

    What is the difference between syntax and static semantics?

    1. A

      Syntax concerns variable values; static semantics concerns the order in which lines execute.

    2. B

      Syntax concerns computer hardware; static semantics concerns the amount of memory available.

    3. C

      Syntax concerns whether a program gives the intended result; static semantics concerns how quickly it runs.

    4. D

      Syntax concerns whether an expression is formed correctly; static semantics concerns whether it has a meaningful interpretation.

    Correct answer
    D

    Syntax concerns whether an expression is formed correctly; static semantics concerns whether it has a meaningful interpretation.

    Explanation

    Syntax addresses whether an expression is structurally valid. Static semantics addresses whether the expression makes sense in the language.

  21. 21

    Why is placing a repetition operator between a string and an integer meaningful in Python, while placing an addition operator between them is not?

    1. A

      Python treats repetition as a syntax rule but treats addition as a comment.

    2. B

      Python allows strings to be added to numbers only when the number is negative.

    3. C

      Python defines string repetition by an integer but does not define adding a string and an integer.

    4. D

      Python automatically converts every integer into a string before addition but not before repetition.

    Correct answer
    C

    Python defines string repetition by an integer but does not define adding a string and an integer.

    Explanation

    The lecture explains that a string multiplied by an integer repeats the string, while a string plus an integer has no defined static meaning in Python.

  22. 22

    Which example best illustrates a syntax error rather than a static semantic error?

    1. A

      A program runs successfully but computes an unintended answer.

    2. B

      A program applies an operator to types for which the operation is undefined.

    3. C

      A program contains malformed structure, such as invalid indentation.

    4. D

      A program repeats a valid calculation more times than necessary.

    Correct answer
    C

    A program contains malformed structure, such as invalid indentation.

    Explanation

    Spelling or indentation problems that make the code structurally invalid are examples of syntax errors. An unsupported operation between types is a static semantic problem.

  23. 23

    How do program meanings differ from the meanings of ambiguous English sentences?

    1. A

      A program's meaning depends on the reader, while English meaning is determined only by grammar.

    2. B

      A program and an English sentence both always have exactly one possible meaning.

    3. C

      A program can have multiple meanings, while an English sentence always has one meaning.

    4. D

      A program follows its instructions in one defined way, while an English sentence can have multiple interpretations.

    Correct answer
    D

    A program follows its instructions in one defined way, while an English sentence can have multiple interpretations.

    Explanation

    The lecture contrasts ambiguous English, which may have multiple meanings, with programs, which have one operational meaning when executed.

  24. 24

    What can happen when a program's actual behavior differs from what its programmer intended?

    1. A

      It automatically changes its instructions to match the programmer's intention.

    2. B

      It may crash, run without stopping, or finish with an incorrect result.

    3. C

      It must produce a syntax error before any instruction runs.

    4. D

      It always terminates successfully with the correct result.

    Correct answer
    B

    It may crash, run without stopping, or finish with an incorrect result.

    Explanation

    The lecture describes programs that crash, run indefinitely, or terminate with an unexpected answer when their behavior does not match the intended meaning.

  25. 25

    What does it mean to say that a computer is “dumb” in the context of the lecture?

    1. A

      It can execute only programs that contain arithmetic and no conditions.

    2. B

      It follows the instructions it is given rather than independently deciding what should be done.

    3. C

      It changes program instructions whenever it detects a better solution.

    4. D

      It cannot store large amounts of data or perform operations quickly.

    Correct answer
    B

    It follows the instructions it is given rather than independently deciding what should be done.

    Explanation

    The lecture uses “dumb” to emphasize that computers follow given sequences of instructions and do not independently decide what the programmer meant.

  26. 26

    Which statement about objects and their types is correct?

    1. A

      An object's type records the programmer's intended purpose for that object.

    2. B

      An object's type is the name assigned to the object in the source code.

    3. C

      An object's type determines which line of the program will execute next.

    4. D

      An object's type tells Python which kinds of operations are allowed for that object.

    Correct answer
    D

    An object's type tells Python which kinds of operations are allowed for that object.

    Explanation

    Python uses an object's type to determine the kinds of operations that can be performed on it.

  27. 27

    Which description correctly distinguishes an integer from a float in the examples given?

    1. A

      An integer represents a truth value, while a float represents a sequence of characters.

    2. B

      An integer represents a whole-number value, while a float can represent values with a decimal point.

    3. C

      An integer is a structured collection, while a float is always a string.

    4. D

      An integer must be positive, while a float must be negative.

    Correct answer
    B

    An integer represents a whole-number value, while a float can represent values with a decimal point.

    Explanation

    The lecture identifies integers as whole numbers and floats as numbers that can include a decimal point; for example, 2.0 is a float.

  28. 28

    Which statement correctly describes Python Boolean values?

    1. A

      A Boolean has one of two values, written with capitalized names: True or False.

    2. B

      A Boolean is a sequence of characters whose value depends on its length.

    3. C

      A Boolean has one value, None, and cannot represent a false condition.

    4. D

      A Boolean can have any numeric value, and its name is always lowercase.

    Correct answer
    A

    A Boolean has one of two values, written with capitalized names: True or False.

    Explanation

    Python's Boolean type has two values, True and False, and their capitalization matters.

  29. 29

    Which statement about the None type is supported by the lecture?

    1. A

      It is another name for every integer value.

    2. B

      It is a type used only for sequences of characters.

    3. C

      It is a type with two values, True and False.

    4. D

      It is a type with one special value, None.

    Correct answer
    D

    It is a type with one special value, None.

    Explanation

    The lecture identifies None as the single special value of the None type.

  30. 30

    What distinguishes a scalar object from a non-scalar object in the lecture's examples?

    1. A

      A scalar object contains multiple elements, while a non-scalar object contains just one.

    2. B

      A non-scalar object has internal structure, while a scalar object does not.

    3. C

      A scalar object can be stored, while a non-scalar object cannot.

    4. D

      A non-scalar object must be a Boolean, while a scalar object must be a string.

    Correct answer
    B

    A non-scalar object has internal structure, while a scalar object does not.

    Explanation

    A list of numbers has structure, such as a first and last number, while a number itself has no such internal structure.

  31. 31

    What does Python's type command report when given an object?

    1. A

      The number of operations already performed on the object.

    2. B

      The variable name most recently assigned to the object.

    3. C

      The type of that object.

    4. D

      The memory location where the object is stored.

    Correct answer
    C

    The type of that object.

    Explanation

    The type command can be used to ask Python for the type of an object.

  32. 32

    What happens when an integer is cast to a float?

    1. A

      The integer is converted to a string of characters.

    2. B

      The integer object is changed in place and no new object is produced.

    3. C

      A new float object is produced; the original integer object is not changed.

    4. D

      The integer is rounded to the nearest whole number and remains an integer.

    Correct answer
    C

    A new float object is produced; the original integer object is not changed.

    Explanation

    Casting creates a new object of the requested type; it does not change the original object that was already created.

  33. 33

    What does converting a positive float to an integer do in the examples discussed?

    1. A

      It rounds the value to the nearest integer in every case.

    2. B

      It converts the value to a Boolean based on whether it is whole.

    3. C

      It preserves the decimal portion but changes the value's type label.

    4. D

      It truncates the decimal portion rather than rounding to the nearest integer.

    Correct answer
    D

    It truncates the decimal portion rather than rounding to the nearest integer.

    Explanation

    The lecture shows that converting values such as 5.2 or 5.9 to integers truncates the decimal portion; it does not round.

  34. 34

    What type results from rounding 5.9 in the example discussed?

    1. A

      A Boolean, because rounding checks whether the value is whole.

    2. B

      A string, because the result is displayed as a numeral.

    3. C

      An integer, because the rounded result is returned as 6.

    4. D

      A float, because the original value contained a decimal point.

    Correct answer
    C

    An integer, because the rounded result is returned as 6.

    Explanation

    The lecture notes that rounding 5.9 produces the integer 6, not the float 6.0.

  35. 35

    Why does dividing one number by another produce a float in the Python behavior described?

    1. A

      The division operator first checks whether the result is an integer and then converts only some results.

    2. B

      The division operator converts both operands to strings before calculating.

    3. C

      The division operator always rounds the result to the nearest whole number.

    4. D

      The division operator produces a float regardless of whether the result is a whole number.

    Correct answer
    D

    The division operator produces a float regardless of whether the result is a whole number.

    Explanation

    The lecture states that ordinary division in Python produces a float regardless of the operand types or whether the result is mathematically whole.

  36. 36

    What is a string, according to the lecture?

    1. A

      A whole number that can be combined only with integers.

    2. B

      A truth value written using lowercase letters.

    3. C

      A collection of instructions stored in the program counter.

    4. D

      A sequence of characters, indicated in Python by quotation marks.

    Correct answer
    D

    A sequence of characters, indicated in Python by quotation marks.

    Explanation

    A string is a sequence of characters, and quotation marks tell Python to interpret the enclosed characters as a string.

  37. 37

    What happens to an expression when Python evaluates it?

    1. A

      Python evaluates only the first operator and stores the remaining expression.

    2. B

      Python stores the expression unchanged and waits for the programmer to simplify it.

    3. C

      Python reduces it to a single result value rather than storing the expression itself.

    4. D

      Python converts every expression into a variable name before calculating it.

    Correct answer
    C

    Python reduces it to a single result value rather than storing the expression itself.

    Explanation

    The lecture emphasizes that Python evaluates an expression to one value and stores the resulting value, not the expression itself.

  38. 38

    What is the type of the result when two integers are added, subtracted, or multiplied in the rules described?

    1. A

      A float in every case.

    2. B

      An integer.

    3. C

      A string containing the result.

    4. D

      A Boolean if the result is positive.

    Correct answer
    B

    An integer.

    Explanation

    Addition, subtraction, and multiplication produce an integer when both operands are integers.

  39. 39

    What happens to the result type of addition, subtraction, or multiplication when at least one operand is a float?

    1. A

      The result is always an integer.

    2. B

      The result is always a Boolean.

    3. C

      The result is a float.

    4. D

      The operation is always a static semantic error.

    Correct answer
    C

    The result is a float.

    Explanation

    For addition, subtraction, and multiplication, the result is a float if either operand is a float.

  40. 40

    What does floor division do in the examples from the lecture?

    1. A

      It gives the integer portion of the quotient by discarding the fractional part.

    2. B

      It gives the remainder after division.

    3. C

      It rounds the quotient to the nearest integer.

    4. D

      It converts the quotient into a decimal string.

    Correct answer
    A

    It gives the integer portion of the quotient by discarding the fractional part.

    Explanation

    The double-slash operator is described as floor or integer division; for example, five divided by three this way gives one.

  41. 41

    What does the percent operator provide in the examples from the lecture?

    1. A

      The quotient as a floating-point value.

    2. B

      The result of raising one number to a power.

    3. C

      The integer portion of the quotient.

    4. D

      The remainder left after division.

    Correct answer
    D

    The remainder left after division.

    Explanation

    The percent operator returns the remainder; for example, five divided by three leaves a remainder of two.

  42. 42

    Which Python operator is used for exponentiation in the examples?

    1. A

      The double-slash operator.

    2. B

      The percent operator.

    3. C

      The double-asterisk operator.

    4. D

      The single-equals operator.

    Correct answer
    C

    The double-asterisk operator.

    Explanation

    The lecture uses the double-asterisk operator for powers, as in two raised to the third power.

  43. 43

    Which order of precedence is described for the arithmetic operators?

    1. A

      Addition and subtraction first, then exponentiation, then multiplication and division.

    2. B

      Remainder first, then addition and subtraction, then multiplication and exponentiation.

    3. C

      Multiplication and division first, then addition and subtraction, then exponentiation.

    4. D

      Exponentiation first, then multiplication, division, and remainder, then addition and subtraction.

    Correct answer
    D

    Exponentiation first, then multiplication, division, and remainder, then addition and subtraction.

    Explanation

    The described precedence is exponentiation, then multiplication, division, and remainder, followed by addition and subtraction.

  44. 44

    How can a programmer change the default order in which parts of an arithmetic expression are evaluated?

    1. A

      By assigning a variable name to each operator.

    2. B

      By placing a comment between the operands.

    3. C

      By using parentheses to group the parts that should be evaluated first.

    4. D

      By changing the type of the final result.

    Correct answer
    C

    By using parentheses to group the parts that should be evaluated first.

    Explanation

    Parentheses can override the usual operator precedence and specify which parts should be evaluated first.

  45. 45

    Why can an expression appear inside a command such as type or a type conversion?

    1. A

      An expression inside a command is treated as a comment rather than as a value.

    2. B

      The inner expression is evaluated first, and its result is then used by the surrounding command.

    3. C

      Commands can accept only variable names, never the results of expressions.

    4. D

      Commands store the expression without evaluating it and return it unchanged.

    Correct answer
    B

    The inner expression is evaluated first, and its result is then used by the surrounding command.

    Explanation

    The lecture explains that when a command contains a computation in parentheses, Python evaluates that inner computation and uses its result.

  46. 46

    What is the value of an expression that divides one integer by another when the quotient is not a whole number?

    1. A

      A floating-point value that includes the fractional part.

    2. B

      The integer quotient with the remainder discarded.

    3. C

      The remainder alone, represented as an integer.

    4. D

      A syntax error because integers cannot be divided.

    Correct answer
    A

    A floating-point value that includes the fractional part.

    Explanation

    Ordinary division produces a float, so a non-whole quotient retains its fractional part.

  47. 47

    What does an assignment statement do in Python?

    1. A

      It creates a permanent relationship that updates both sides automatically.

    2. B

      It asserts that the values on both sides are mathematically equal.

    3. C

      It binds a variable name to the value produced by the right-hand side.

    4. D

      It asks Python to solve for the variable on the left-hand side.

    Correct answer
    C

    It binds a variable name to the value produced by the right-hand side.

    Explanation

    An assignment binds a name to a value; the equals sign is not being used to state mathematical equality.

  48. 48

    In evaluating an assignment statement, what does Python do first?

    1. A

      It evaluates the right-hand side to a value, then binds that value to the name on the left.

    2. B

      It evaluates the left-hand side and uses it to select a value from the right.

    3. C

      It checks whether the left and right sides are equal, then stores both sides.

    4. D

      It assigns the left-hand name to the unevaluated right-hand expression, then calculates later.

    Correct answer
    A

    It evaluates the right-hand side to a value, then binds that value to the name on the left.

    Explanation

    Python first evaluates the right-hand side of an assignment and then associates its resulting value with the variable name on the left.

  49. 49

    Which form is allowed for the left-hand side of an ordinary assignment in the examples?

    1. A

      A quoted string followed by a variable name.

    2. B

      A numeric value followed by an equals sign.

    3. C

      A single variable name.

    4. D

      A mathematical expression containing an operator.

    Correct answer
    C

    A single variable name.

    Explanation

    The lecture states that an assignment has one variable on the left-hand side; a number or an expression with an operator cannot be used there as a variable name.

  50. 50

    Why does the statement that assigns a value to a variable and later uses that variable not automatically update other variables calculated from it?

    1. A

      Python ignores assignments that use values from another variable.

    2. B

      Python permanently links every calculated value to all variables used to make it.

    3. C

      Python recalculates earlier statements only when the original value is an integer.

    4. D

      Python executes the statements in order and does not recompute earlier assignments unless instructed.

    Correct answer
    D

    Python executes the statements in order and does not recompute earlier assignments unless instructed.

    Explanation

    An earlier result is not automatically recalculated when one of its inputs changes. The program must include another assignment to compute the result again.

  51. 51

    What happens when a variable is rebound to a new value?

    1. A

      The variable name becomes a mathematical equation between the values.

    2. B

      The variable name refers to the new value instead of its previous value.

    3. C

      The program automatically updates every value previously calculated from the variable.

    4. D

      The previous and new values are both assigned to that one variable name.

    Correct answer
    B

    The variable name refers to the new value instead of its previous value.

    Explanation

    Rebinding replaces the name's association with its former value with an association to the new value.

  52. 52

    Why is a temporary variable useful when swapping the values of two variables?

    1. A

      It preserves one original value before the other variable is reassigned.

    2. B

      It makes Python treat assignment as a test of equality.

    3. C

      It forces both variables to have the same value temporarily and permanently.

    4. D

      It prevents the program from evaluating the right-hand side of assignments.

    Correct answer
    A

    It preserves one original value before the other variable is reassigned.

    Explanation

    Saving one original value in a temporary variable prevents it from being lost when the other variable is reassigned.

  53. 53

    Why does the direct sequence of assigning one variable to the other and then reversing the assignment fail to swap their values?

    1. A

      The first assignment overwrites one original value before it can be saved.

    2. B

      The equals sign compares the variables rather than assigning their values.

    3. C

      The second assignment automatically restores the overwritten value.

    4. D

      Python does not allow one variable to be assigned the value of another.

    Correct answer
    A

    The first assignment overwrites one original value before it can be saved.

    Explanation

    After the first assignment, both names can refer to the same original value, so the other original value has been lost unless it was saved first.

  54. 54

    What is the purpose of comments in a program, as described in the lecture?

    1. A

      They make a syntactically invalid expression valid.

    2. B

      They assign a value to every variable in the next code block.

    3. C

      They provide explanatory text for people reading the code and are not program instructions.

    4. D

      They tell Python to repeat the line that follows them.

    Correct answer
    C

    They provide explanatory text for people reading the code and are not program instructions.

    Explanation

    Comments are explanatory text for the programmer or other readers; a line beginning with a hash is treated as a comment rather than an instruction.

  55. 55

    Which variable-naming approach best supports readable code?

    1. A

      Use single-letter names for every variable, regardless of its purpose.

    2. B

      Use operator symbols as names to show how each value is calculated.

    3. C

      Use names that are unrelated to the values so the code stays concise.

    4. D

      Use descriptive names that help readers understand what the values represent.

    Correct answer
    D

    Use descriptive names that help readers understand what the values represent.

    Explanation

    Descriptive variable names make programs easier to read and understand, including when someone revisits or shares the code.

  56. 56

    What is the main benefit of using a variable name for a value such as an approximation of pi?

    1. A

      The value can be referenced conveniently in multiple places, making code clearer and easier to write.

    2. B

      The value automatically changes whenever the radius changes.

    3. C

      The variable name prevents the value from being stored in memory.

    4. D

      Python can then treat the value as exact, regardless of its precision.

    Correct answer
    A

    The value can be referenced conveniently in multiple places, making code clearer and easier to write.

    Explanation

    A name lets a programmer reuse a value without repeatedly copying a long number and can make the program easier to read.

  57. 57

    How does Python Tutor help when examining a program?

    1. A

      It automatically replaces every incorrect algorithm with a correct one.

    2. B

      It lets a learner step through execution and observe variable values at each step.

    3. C

      It guarantees that a program's logic matches the programmer's intention.

    4. D

      It translates comments into executable instructions.

    Correct answer
    B

    It lets a learner step through execution and observe variable values at each step.

    Explanation

    Python Tutor is described as a debugging aid that steps through code and displays variable values as execution proceeds.

  58. 58

    What is the execution order for a program consisting of ordinary sequential statements, before control-flow structures are introduced?

    1. A

      Python selects statements at random based on their variable types.

    2. B

      Python proceeds from the top and executes the statements one after another.

    3. C

      Python repeatedly executes every statement until a variable changes.

    4. D

      Python executes the last statement first and then works toward the top.

    Correct answer
    B

    Python proceeds from the top and executes the statements one after another.

    Explanation

    The lecture emphasizes that, so far, statements execute line by line from the top; branching and repetition are introduced later.

Question 1 of 58
Question 1 of 58

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent