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

  • 69Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Computational Thinking

What three broad outcomes does learning programming aim to develop: what kinds of knowledge or abilities are involved?

69 questions

  1. 1

    What three broad outcomes does learning programming aim to develop: what kinds of knowledge or abilities are involved?

    Model answer

    They are knowledge of computer science concepts, programming skill, and problem-solving skill.

    Explanation

    These outcomes involve understanding ideas, being able to write code, and using computational ideas to solve problems.

  2. 2

    What does computational thinking encourage someone to ask when faced with a problem?

    Model answer

    It encourages them to consider how computation could help solve the problem, rather than relying only on a mathematical or manual solution.

    Explanation

    Computational thinking applies computation to problems, including ones that might also be solved mathematically or by hand.

  3. 3

    How does solving a problem in English relate to writing a program to solve it?

    Model answer

    Identify computer science concepts that apply to the problem, then translate those concepts into a program.

    Explanation

    Programming involves moving from a problem description to suitable computational ideas and then to code.

  4. 4

    Why does learning to program require active practice rather than only watching someone write code?

    Model answer

    Programming is a skill that develops through doing it repeatedly; watching code does not provide the practice needed to perform it independently.

    Explanation

    Frequent practice helps programming actions become more familiar and automatic.

  5. 5

    What does it mean to organize code so that it is readable and modular?

    Model answer

    It means structuring code into clear, manageable parts instead of leaving it as an unorganized collection of statements.

    Explanation

    Organized, readable, modular code is easier to understand and work with.

  6. 6

    What question does algorithmic complexity help answer?

    Model answer

    It helps assess how efficient a program is, including how quickly it runs and how much memory it uses.

    Explanation

    Efficiency can be considered in terms of both execution time and memory use.

  7. 7

    Why might two algorithms that perform the same task be compared?

    Model answer

    They can be compared to determine which is more efficient, for example in speed or memory use.

    Explanation

    Different algorithms can accomplish the same task with different efficiency.

  8. 8

    What is declarative knowledge, and why is it not enough by itself to direct a computer?

    Model answer

    Declarative knowledge states a fact or relationship. By itself, it does not tell a computer what steps to perform to obtain a result.

    Explanation

    A computer needs instructions describing how to carry out a task, not merely a statement about a fact.

  9. 9

    What is imperative knowledge in programming?

    Model answer

    Imperative knowledge is a recipe or set of instructions that specifies how to do something.

    Explanation

    A program gives the computer steps to follow to accomplish a task.

  10. 10

    Why would the statement “y×y=xy \times y = xy×y=x” not be a sufficient instruction for a computer to find a square root?

    Model answer

    It describes a relationship but does not specify a procedure for finding a value of yyy. The computer needs steps for searching for the square root.

    Explanation

    A computer requires an actionable recipe rather than only a mathematical description.

  11. 11

    Describe the basic iterative recipe for approximating the square root of xxx using a guess GGG.

    Model answer

    Check whether G2G^2G2 is close enough to xxx; if not, replace GGG with the average of GGG and x/Gx/Gx/G, then repeat the check.

    Explanation

    Each new guess is calculated as G+x/G2\frac{G + x/G}{2}2G+x/G​ and is tested again.

  12. 12

    How does the square-root procedure determine when to stop?

    Model answer

    It stops when the current guess is close enough to the square root according to a chosen tolerance.

    Explanation

    The acceptable closeness can vary; a rough tolerance may be sufficient, while a tighter one requires more iterations.

  13. 13

    What three structural features do algorithms share with ordinary recipes?

    Model answer

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

    Explanation

    Recipes can include conditional instructions, repetition, and a stopping condition, just like algorithms.

  14. 14

    What is meant by flow of control in an algorithm?

    Model answer

    Flow of control describes how execution moves through the steps, including decisions to take different actions or repeat steps.

    Explanation

    An algorithm need not execute only in a simple straight line; conditions and repetition can change the path.

  15. 15

    Why must an algorithm have a stopping condition?

    Model answer

    A stopping condition allows the algorithm to finish rather than continuing indefinitely.

    Explanation

    For the square-root method, the procedure stops once the guess meets the selected accuracy requirement.

  16. 16

    What does it mean to say that computers execute algorithms?

    Model answer

    Computers carry out the sequences of steps specified by algorithms.

    Explanation

    A computer follows the instructions it is given rather than inventing its own steps.

  17. 17

    What two capabilities make computers especially useful, and what important limitation was emphasized?

    Model answer

    Computers can store large amounts of data and perform operations quickly, but they do not make decisions unless instructed to do so.

    Explanation

    Their speed and storage are strengths; they follow specified instructions rather than acting intelligently on their own.

  18. 18

    How did fixed-program computers such as pocket calculators differ from stored-program computers?

    Model answer

    A fixed-program computer had built-in operations but could not store a reusable sequence of operations for different inputs. A stored-program computer could store instructions as data.

    Explanation

    With a fixed-program calculator, the user had to enter the sequence of operations again for each input.

  19. 19

    What role did an interpreter play in early stored-program computers?

    Model answer

    It executed stored instructions by following their steps, including moving to another instruction when directed.

    Explanation

    The interpreter knew how to carry out the program’s instructions in sequence and follow changes in control.

  20. 20

    What basic kinds of instructions did the early stored-program computers described in the lecture perform?

    Model answer

    They performed arithmetic, logical tests, and data movement between memory locations.

    Explanation

    Examples include addition, subtraction, equality comparisons, and moving a value to another memory location.

  21. 21

    What are the roles of memory, the arithmetic logic unit, and the control unit in the simplified computer model?

    Model answer

    Memory stores values and instructions; the arithmetic logic unit performs calculations and comparisons; the control unit manages instruction execution, including the program counter.

    Explanation

    Together these components support storing, processing, and directing the execution of a program.

  22. 22

    In the example of adding two stored values, what steps occur before the result is saved?

    Model answer

    The interpreter retrieves the values from memory, sends them to the arithmetic logic unit, and the unit calculates their sum. A later instruction stores that result at a specified memory location.

    Explanation

    The addition and the instruction to store its result are separate operations.

  23. 23

    What does the example of comparing two stored sums and printing the result illustrate?

    Model answer

    A program can use instructions to retrieve values, compare them, and print the comparison result, such as True when the values are equal.

    Explanation

    The arithmetic logic unit performs the comparison, and a subsequent instruction prints its result.

  24. 24

    What did Alan Turing’s result about computation imply for programming languages?

    Model answer

    Anything computable in one programming language is computable in another, because programs can be represented using sufficiently basic operations and rebuilt in another language.

    Explanation

    The result shows that different languages can express the same computations, even if their instructions differ.

  25. 25

    What six basic operations were cited as sufficient primitives in Turing’s tape-based model?

    Model answer

    Move the tape left, move it right, read a value, write a value, erase a value, and perform no operation.

    Explanation

    The lecture used these primitives to illustrate how very simple operations can support general computation.

  26. 26

    How do primitives in a programming language relate to more complex programs?

    Model answer

    Basic primitives can be combined to form expressions and larger programs, much as characters form words and words form sentences in English.

    Explanation

    More complex structures are built from simpler elements, though programming languages have their own rules for combining them.

  27. 27

    What is the difference between syntax and static semantics in a programming language?

    Model answer

    Syntax concerns whether code has a valid form; static semantics concerns whether the validly formed code has an acceptable meaning under the language’s rules.

    Explanation

    An expression can be syntactically valid yet still combine objects or operations in a way that has no defined meaning.

  28. 28

    Why is "Hi" 5 not a meaningful Python expression, while "Hi" * 5 is?

    Model answer

    Python does not define placing a string and a number side by side as an operation. The * operator gives the combination a meaning: repeat the string five times.

    Explanation

    A valid expression needs an operator with a defined meaning for the objects it combines.

  29. 29

    What is the result of evaluating "Hi" * 5 in Python?

    Model answer

    It produces the string "HiHiHiHiHi".

    Explanation

    Multiplying a string by an integer repeats the string that number of times.

  30. 30

    Why is "Hi" + 5 an example of a static semantic error in the lecture’s Python examples?

    Model answer

    Although it has the form object-operator-object, Python does not define addition between a string and an integer in that example.

    Explanation

    The expression’s form is syntactically valid, but the operation is not meaningful for those object types.

  31. 31

    How does ambiguity in ordinary-language meaning differ from the meaning of a program?

    Model answer

    A sentence in ordinary language can have multiple interpretations, but a program’s instructions have one execution meaning for the computer, even if that meaning differs from the programmer’s intention.

    Explanation

    The computer follows the program’s instructions rather than resolving them according to intended meaning.

  32. 32

    What are three possible outcomes when a program’s behavior does not match the programmer’s intention?

    Model answer

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

    Explanation

    These are examples of errors arising from a mismatch between intended and actual program behavior.

  33. 33

    How do syntax errors, static semantic errors, and errors of intended program behavior differ?

    Model answer

    Syntax errors violate the language’s form, static semantic errors use valid forms in an invalid way, and behavior errors occur when a program runs but does not do what was intended.

    Explanation

    The first two concern the code’s form or permitted operations; the last concerns the program’s actual behavior.

  34. 34

    What is an object in a program, and what does its type tell Python?

    Model answer

    An object is a value used by a program; its type tells Python what kinds of operations are allowed on it.

    Explanation

    For example, numeric values support arithmetic, while strings support operations such as measuring their length or selecting a character.

  35. 35

    What is the difference between scalar and non-scalar objects?

    Model answer

    A scalar object, such as a number or truth value, is a single value without internal structure in this sense. A non-scalar object, such as a list, has structure made up of parts.

    Explanation

    A list can contain elements at positions, whereas a number is treated as one value.

  36. 36

    What are the four scalar types introduced in the lecture, and what values characterize each?

    Model answer

    int represents integers, float represents floating-point numbers, bool represents True or False, and NoneType has the single value None.

    Explanation

    The Boolean type has two values, while NoneType has one; integer and float types can have many values.

  37. 37

    How do 5 and 5.0 differ in Python?

    Model answer

    5 is an int, while 5.0 is a float, even though they represent the same whole-number quantity.

    Explanation

    The presence of a decimal point in the literal makes 5.0 a float.

  38. 38

    What is a string, and how do quotation marks function when creating one?

    Model answer

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

    Explanation

    For example, 'Anna' contains the characters inside the quotes rather than a numeric value.

  39. 39

    What are examples of operations that make sense for a string but not for a number?

    Model answer

    A program can ask for a string’s length, select a character at a position, or identify its middle character.

    Explanation

    These operations depend on the string’s sequence of characters, which a number does not have.

  40. 40

    How can a programmer ask Python to identify the type of an object?

    Model answer

    Use type(object), placing the object or an expression inside the parentheses.

    Explanation

    For example, type(7) reports int, while type(0.0) reports float.

  41. 41

    Why does capitalization matter for Python’s Boolean values?

    Model answer

    Python uses the capitalized names True and False; lowercase true is not recognized as the same value and can cause a name error.

    Explanation

    Python is case-sensitive, so the capitalization of these special values must be correct.

  42. 42

    What does casting do, and does it change the original object?

    Model answer

    Casting creates a value of a different type from an existing value; it does not change the original object.

    Explanation

    For example, casting integer 3 to a float produces 3.0 as a new value.

  43. 43

    What does float(3) produce, and what happens to the original integer?

    Model answer

    It produces the float 3.0; the original integer 3 remains unchanged.

    Explanation

    Casting creates a float version rather than modifying the integer object.

  44. 44

    What happens when a float such as 5.9 is cast to an integer with int()?

    Model answer

    The fractional part is truncated, so int(5.9) produces 5; it does not round to 6.

    Explanation

    The conversion keeps the integer portion rather than rounding the float.

  45. 45

    What type does round(7.9) produce in the example from the lecture, and why?

    Model answer

    It produces an integer, because rounding gives the whole-number result 8.

    Explanation

    The lecture contrasts this with casting a float to an integer, which truncates rather than rounds.

  46. 46

    What value and type result from int(7.2)?

    Model answer

    It produces the integer 7.

    Explanation

    The fractional part is discarded when the float is cast to an integer.

  47. 47

    How is the value of an expression handled by Python?

    Model answer

    Python evaluates the expression to one value and stores or uses that result; it does not store the expression itself as an unevaluated formula.

    Explanation

    For example, 3 + 2 evaluates to the value 5.

  48. 48

    What type results from adding, subtracting, or multiplying two integers?

    Model answer

    The result is an integer.

    Explanation

    If at least one operand in these operations is a float, the result is a float.

  49. 49

    What type results from dividing numbers with / in Python?

    Model answer

    Division with / produces a float, regardless of whether the operands are integers or floats.

    Explanation

    For example, dividing two integers can still produce a floating-point result.

  50. 50

    What do the // and % operators calculate?

    Model answer

    // gives the floor-division result, while % gives the remainder after division.

    Explanation

    For example, 5 // 3 is 1 and 5 % 3 is 2.

  51. 51

    What does the ** operator do, and how can operand types affect its result?

    Model answer

    ** performs exponentiation; if an operand is a float, the result is a float.

    Explanation

    For example, 2 ** 3 gives 8, while using a float operand gives a float result.

  52. 52

    What is the precedence order for the arithmetic operators introduced in the lecture?

    Model answer

    Exponentiation is evaluated first, then multiplication, division, floor division, and remainder, and finally addition and subtraction.

    Explanation

    Parentheses can override the usual precedence order.

  53. 53

    How can parentheses affect the evaluation of an expression?

    Model answer

    Parentheses can change the order in which parts of an expression are evaluated; for nested function calls, the innermost parenthesized expression is evaluated first.

    Explanation

    This lets a programmer override ordinary operator precedence or supply a computed value to a function.

  54. 54

    Why use a variable name for a value such as an approximation of pi instead of repeatedly typing the number?

    Model answer

    A name avoids repeated copying of a long value and makes code easier to read and maintain.

    Explanation

    Descriptive names also help readers understand what a value represents.

  55. 55

    How does a computer science variable differ from the idea of a variable in declarative mathematics?

    Model answer

    In programming, a variable name is bound to one value at a time; it is not a statement that the name represents a set of possible values or an equation to solve.

    Explanation

    Programming uses imperative assignment to associate names with values.

  56. 56

    What does the assignment statement m = 10 mean in Python?

    Model answer

    It binds the name m to the value 10; the equals sign indicates assignment, not a claim of mathematical equality.

    Explanation

    The assignment associates a variable name with a value so the program can use that value later.

  57. 57

    In an assignment such as f = m * 9.98, what happens first?

    Model answer

    Python evaluates the right-hand expression using the current value of m, then binds the resulting value to f.

    Explanation

    Assignments evaluate the right-hand side before updating the name on the left.

  58. 58

    Why is x = 6 valid while 6 = x is not?

    Model answer

    An assignment requires a variable name on the left and a value or expression on the right; 6 is a value, not a variable name.

    Explanation

    Python cannot assign a new value to a numeric literal.

  59. 59

    Why is x * y = 3 + 4 invalid, while xy = 3 + 4 is allowed?

    Model answer

    The left side of an assignment must be a variable name, not an expression containing an operator. xy is a valid name, so it can be assigned the result.

    Explanation

    The characters x and y together form a name; the * in x * y is an operator.

  60. 60

    Why should programmers choose descriptive variable names rather than unexplained single-letter names?

    Model answer

    Descriptive names make a program easier for the original programmer and other readers to understand later.

    Explanation

    Names should indicate what their values represent in the program.

  61. 61

    What is a comment in Python, and what is its purpose?

    Model answer

    A comment is explanatory text beginning with #; it helps readers understand the purpose of code and is not an executable statement.

    Explanation

    Comments are often most useful when they explain a larger section of code rather than merely restating each line.

  62. 62

    What makes a code comment useful rather than redundant?

    Model answer

    A useful comment explains the purpose or intent of a section of code instead of simply describing the operations that are already obvious from the code.

    Explanation

    For example, a comment can say that a section calculates area and circumference using an approximation for pi.

  63. 63

    What happens when a variable is assigned a new value?

    Model answer

    The name is rebound to the new value, replacing its previous binding; the old value may remain in memory until it is reclaimed.

    Explanation

    A variable name refers to one value at a time, though the previous object can still exist independently.

  64. 64

    How is radius = radius + 1 evaluated in Python?

    Model answer

    Python reads the current value of radius, adds 1, and then rebinds radius to the result.

    Explanation

    The right-hand side is evaluated first, so the statement does not express a mathematical equation to solve.

  65. 65

    If a program calculates area and then changes radius, what happens to area automatically?

    Model answer

    Nothing; area keeps its previously calculated value unless the program explicitly calculates it again.

    Explanation

    The computer follows the written instructions and does not infer that a dependent value should be updated.

  66. 66

    In what order does a simple program execute its statements when no control-flow instructions are present?

    Model answer

    It executes them one after another, starting at the top and proceeding line by line.

    Explanation

    Repetition and decision points require instructions that have not yet been introduced in a simple straight-line program.

  67. 67

    How can a programmer swap the values of x and y without losing either original value?

    Model answer

    Save one value in a temporary variable, assign the other variable’s value to the first, then assign the saved value to the second.

    Explanation

    The temporary variable preserves a value that would otherwise be lost during reassignment.

  68. 68

    Why does directly executing y = x followed by x = y fail to swap two values?

    Model answer

    The first assignment overwrites y with the old value of x, so the original value of y is lost before it can be assigned to x.

    Explanation

    A temporary variable is needed to preserve one of the original values.

  69. 69

    How can a step-by-step execution tool help debug a program?

    Model answer

    It lets the programmer inspect the program one statement at a time and see the values bound to variables after each step.

    Explanation

    Watching values change can reveal where a program’s behavior departs from what was intended.

1 of 69
Question 1 of 69

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent