1. Home
  2. Explore
  3. Computer Science
  4. Computer Science Introduction

Study methods

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

Computer Science Introduction

  • 66Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered

What is the primary goal of CS 50, according to the instructor?

66 questions

  1. 1

    What is the primary goal of CS 50, according to the instructor?

    Model answer

    The overarching goal of CS 50 is to teach students how to think, how to take input and produce correct output, and how to master the tools of computer science.

    Explanation

    The instructor explicitly states that CS 50 is not just about teaching programming, but more fundamentally about developing computational thinking skills. This involves learning to approach problems systematically, understanding how to transform inputs into desired outputs, and becoming proficient with the various instruments and methodologies used in computer science.

  2. 2

    How does the instructor describe the role of artificial intelligence (AI) in programming?

    Model answer

    AI is changing programming by assisting in problem-solving, bug fixing, and adding new features to software, significantly increasing efficiency and capabilities.

    Explanation

    The instructor views AI as an exciting development that empowers programmers by offloading tedious tasks. AI can help automate parts of the coding process, identify and correct errors, and even generate new functionalities, thereby making human programmers more productive and less of a 'bottleneck'.

  3. 3

    Despite the advancements in AI, why does the instructor emphasize understanding programming fundamentals?

    Model answer

    Understanding fundamentals is crucial because programmers remain in the 'driver's seat,' guiding AI tools and comprehending the underlying processes to solve problems effectively.

    Explanation

    The analogy of a 'pilot' or 'conductor' is used to illustrate that while AI can assist, the human programmer still directs the process. A strong grasp of fundamentals ensures that programmers can critically evaluate AI-generated solutions, debug complex issues, and articulate what they want the computer to do, rather than simply relying on AI without understanding.

  4. 4

    What is Visual Studio Code (VS Code) and how is it characterized?

    Model answer

    VS Code is a popular, largely open-source or free text editor used by professionals to write code, similar to a word processor but without formatting features.

    Explanation

    VS Code is introduced as a widely used tool in the industry for software development. It functions primarily as a text editor, meaning it's designed for writing plain text code, unlike word processors that focus on document formatting. Its open-source nature makes it accessible and popular.

  5. 5

    What is an Application Programming Interface (API) in the context of the chatbot demonstration?

    Model answer

    An API is a set of functionalities and features provided by a company (like OpenAI) that allows other programmers to write their own code to interact with and utilize those services.

    Explanation

    In the chatbot example, OpenAI provides an API, which essentially acts as a bridge. It allows the Python program to 'talk' to OpenAI's powerful AI models (like GPT-5) without needing to understand or recreate the complex underlying AI technology. The API defines how a developer can request and receive responses from OpenAI's service.

  6. 6

    What is the purpose of a 'model' in the context of AI, as mentioned in the chatbot example?

    Model answer

    An AI model, such as GPT-5, is a statistical model that drives the capabilities and behavior of artificial intelligence systems.

    Explanation

    AI models are the core intelligence of AI systems. They are trained on vast amounts of data to recognize patterns, understand language, and generate responses. The specific model chosen, like GPT-5, dictates the sophistication and performance of the AI's output.

  7. 7

    How can a chatbot program be made more dynamic to accept various user questions?

    Model answer

    A chatbot can be made dynamic by using an input function to prompt the user for a question and storing that question in a variable, which is then passed to the AI.

    Explanation

    Initially, the chatbot was 'hard-coded' to ask only one question. To make it dynamic, the input() function allows the program to pause and wait for the user to type in their own question. This user-provided question is then stored in a prompt variable and used as input for the AI, making the chatbot interactive and versatile.

  8. 8

    What is the difference between a 'user prompt' and a 'system prompt' when interacting with an AI?

    Model answer

    A user prompt is the direct question or instruction from the human, while a system prompt is a set of standardized instructions given to the AI to guide its overall behavior, like limiting answer length or adopting a persona.

    Explanation

    The user prompt is the specific query the human wants an answer to (e.g., 'What is CS 50?'). The system prompt, on the other hand, is a meta-instruction that influences how the AI processes all subsequent user prompts. It allows developers to define the AI's role, style, or constraints, ensuring consistent behavior without the user having to repeat those instructions.

  9. 9

    What is the 'rubber duck debugging' technique in programming, and how does CS 50 apply it?

    Model answer

    Rubber duck debugging involves explaining a programming problem aloud to an inanimate object to help verbalize confusion and identify mistakes. CS 50 provides a virtual AI-based 'rubber duck' for students to use.

    Explanation

    This technique leverages the psychological principle that articulating a problem often helps clarify it. By forcing oneself to explain the code and the issue to a 'duck,' programmers often spot their own logical errors. CS 50's virtual duck is an AI tutor designed to mimic a human tutor, guiding students to solutions without simply giving them the answer.

  10. 10

    What are the core concepts of 'computational thinking'?

    Model answer

    Computational thinking is the application of ideas from computer science to solve problems generally in the real world, focusing on representation and processing of information.

    Explanation

    It's not just about using computers, but about developing a mindset derived from computer science principles. This involves breaking down complex problems, recognizing patterns, designing algorithms, and abstracting information to find effective and efficient solutions, even outside of traditional computing contexts.

  11. 11

    How is a 'problem' typically distilled in computer science?

    Model answer

    A problem is distilled as having an input (the problem itself), an output (the desired solution), and a 'black box' in the middle that processes the input to produce the output.

    Explanation

    This simple model, often depicted as a diagram, frames problem-solving. The 'black box' represents the unknown or the process that needs to be designed – the algorithm that transforms the given input into the required output. This abstraction allows for focusing on the 'what' (input/output) and the 'how' (the processing within the black box).

  12. 12

    What is the fundamental way computers represent information?

    Model answer

    Computers fundamentally represent all information using zeros and ones, known as binary digits or bits.

    Explanation

    Regardless of whether it's text, numbers, images, or sound, everything inside a computer is ultimately converted into sequences of 0s and 1s. This is because computers operate on simple electrical states (on/off, high/low voltage), which are perfectly mapped to binary values.

  13. 13

    Explain the concept of 'unary notation' or 'base one'.

    Model answer

    Unary notation (base one) is a system where numbers are represented by repeating a single symbol, like counting on fingers by extending one finger at a time.

    Explanation

    This is the simplest counting system, where each unit is represented by one mark (e.g., I for 1, II for 2, III for 3). It's very intuitive but highly inefficient for larger numbers, as it requires as many symbols as the number being represented.

  14. 14

    How high can one count on a single human hand using binary representation, and why?

    Model answer

    One can count as high as 31 on a single human hand using binary, because each of the five fingers can represent a power of two (on/off), yielding 25=322^5 = 3225=32 total combinations, with 0 being the first.

    Explanation

    Unlike unary counting where each finger represents one unit, in binary, each finger acts as a bit. With five fingers, you have five bits. Each finger's state (up or down) corresponds to a 0 or 1. The positions represent 20,21,22,23,242^0, 2^1, 2^2, 2^3, 2^420,21,22,23,24. The highest number achievable is when all fingers are 'up' (11111 in binary), which sums to 16+8+4+2+1=3116+8+4+2+1 = 3116+8+4+2+1=31. Including the 'all fingers down' state (0), there are 32 possible patterns.

  15. 15

    What is a 'bit' in computer science, and what are its two possible states?

    Model answer

    A bit is a single binary digit, which can represent either a 0 or a 1.

    Explanation

    The term 'bit' is a portmanteau of 'binary digit'. It's the smallest unit of data in computing. These two states, 0 and 1, are physically represented by the presence or absence of an electrical signal, or the on/off state of a transistor.

  16. 16

    How do computers physically represent zeros and ones?

    Model answer

    Computers represent zeros and ones using electrical signals; for example, a light bulb being off represents 0, and on represents 1, or more commonly, transistors switching on and off.

    Explanation

    The simplicity of binary is advantageous because it maps directly to physical phenomena. An electrical current flowing (on) or not flowing (off) is a clear distinction. Transistors act as tiny switches that can hold these electrical states, making it very efficient and reliable for computers to store and process information.

  17. 17

    What is the 'base 10 system' and why is it also called 'decimal'?

    Model answer

    The base 10 system, or decimal, uses ten distinct digits (0 through 9) and is called 'decimal' from 'dec,' implying ten.

    Explanation

    This is the number system most humans use daily. It's base 10 because there are 10 symbols available. The value of a digit depends on its position, representing powers of 10 (ones place, tens place, hundreds place, etc.).

  18. 18

    Explain how the decimal number 123 is derived in the base 10 system.

    Model answer

    The number 123 in base 10 is derived by summing the products of each digit with its corresponding power of 10: (1×100)+(2×10)+(3×1)=123(1 \times 100) + (2 \times 10) + (3 \times 1) = 123(1×100)+(2×10)+(3×1)=123.

    Explanation

    In the decimal system, the rightmost digit is the 'ones place' (10010^0100), the next is the 'tens place' (10110^1101), then the 'hundreds place' (10210^2102), and so on. So, for 123, it's 1 hundred, 2 tens, and 3 ones.

  19. 19

    Why is the binary system (base 2) preferred for computers over base 10?

    Model answer

    Binary is preferred because it's simpler for hardware to distinguish between two states (on/off electricity) than ten distinct levels of electricity, making computers easier to build and more reliable.

    Explanation

    While it's theoretically possible to design hardware for a base 10 system, it would be much more complex to create and maintain circuits that can reliably differentiate between ten precise voltage levels. The binary system's simplicity of 'on' or 'off' (0 or 1) aligns perfectly with the physical nature of electrical signals.

  20. 20

    How is the binary number 111 (three bits) converted to its decimal equivalent?

    Model answer

    The binary number 111 is converted to decimal by summing the powers of two corresponding to the 'on' bits: (1×4)+(1×2)+(1×1)=7(1 \times 4) + (1 \times 2) + (1 \times 1) = 7(1×4)+(1×2)+(1×1)=7.

    Explanation

    In base 2, the column weights are powers of two, starting from 202^020 on the right. So, for 111, the positions represent 222^222 (4), 212^121 (2), and 202^020 (1). Since all bits are 1, you sum 4+2+1=74+2+1=74+2+1=7. Thus, 111 binary is 7 decimal.

  21. 21

    What potential problem arises if a computer doesn't have enough 'bits' or memory to store a number?

    Model answer

    If a computer lacks sufficient bits, it might 'overflow' and count back to zero after reaching its maximum capacity, leading to incorrect calculations and real-world problems.

    Explanation

    This is known as integer overflow. For example, if a system can only store up to 7 (using 3 bits), trying to represent 8 would cause it to 'wrap around' and become 0 again because there's no fourth bit to represent the value of 8. This can lead to unexpected behavior or crashes in software if not handled.

  22. 22

    What is a 'byte' in computer science, and how many bits does it contain?

    Model answer

    A byte is a unit of measure consisting of 8 bits.

    Explanation

    While bits are the smallest units, bytes are a more common grouping for practical purposes. Historically, 8 bits were chosen as a convenient unit for representing characters and other data, allowing for 28=2562^8 = 25628=256 different values.

  23. 23

    What is the maximum decimal number that can be represented by one byte (8 bits)?

    Model answer

    One byte (8 bits) can represent a maximum decimal number of 255 if all bits are 'on' (11111111 in binary).

    Explanation

    With 8 bits, the values represented are 27,26,25,24,23,22,21,202^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^027,26,25,24,23,22,21,20. If all these positions are 1, their sum is 128+64+32+16+8+4+2+1=255128+64+32+16+8+4+2+1 = 255128+64+32+16+8+4+2+1=255. Including 0, this provides 256 total possibilities (282^828).

  24. 24

    Why is the number 256 commonly encountered in computer science?

    Model answer

    256 is common because it represents the total number of unique values (from 0 to 255) that can be stored in one byte (8 bits), which is 282^828.

    Explanation

    Many early computer systems and graphics formats were designed around 8-bit processing. This means that features like the number of colors on a screen or the range of certain values were limited to 256 possibilities, making it a foundational number in computing.

  25. 25

    How many unique values can 32 bits represent, approximately?

    Model answer

    32 bits can represent approximately 4 billion unique values (2322^{32}232).

    Explanation

    This vast number allows computers to handle very large integers, memory addresses, and other data types. When accounting for negative numbers (signed integers), the range typically splits, offering approximately 2 billion positive and 2 billion negative values.

  26. 26

    How do computers store letters of the alphabet, like the capital letter 'A'?

    Model answer

    Computers store letters by assigning each letter a specific integer value, which is then represented in binary (zeros and ones). For example, 'A' is standardized as 65.

    Explanation

    Since computers only understand binary, a numerical mapping is necessary. Standards like ASCII (and later Unicode) were created to assign unique numbers to characters. When a computer encounters the binary representation of 65 in a text context, it displays it as 'A'.

  27. 27

    What is ASCII, and what was its original purpose?

    Model answer

    ASCII (American Standard Code for Information Interchange) is a standard mapping of letters, numbers, and symbols to corresponding numerical values, created to standardize character representation for computers.

    Explanation

    Developed by a group of Americans, ASCII was one of the earliest character encoding schemes. It provided a common language for different computers to understand and exchange text data by agreeing that specific numerical patterns would represent specific characters.

  28. 28

    How many bits did ASCII originally use, and how many unique characters could it represent?

    Model answer

    ASCII originally used 7 bits, allowing it to represent 27=1282^7 = 12827=128 unique characters. It was later extended to 8 bits for 256 characters.

    Explanation

    The initial 7-bit ASCII was sufficient for English uppercase and lowercase letters, numbers, and basic punctuation. The extension to 8 bits allowed for an additional 128 characters, including some international characters and graphical symbols.

  29. 29

    What is the numerical relationship between uppercase and lowercase letters in ASCII, and how can a computer change a letter's case?

    Model answer

    Lowercase letters are consistently 32 units higher than their uppercase counterparts in ASCII. A computer can change case by flipping a single bit in the 32's place of the character's 8-bit binary representation.

    Explanation

    For example, 'A' is 65 and 'a' is 97 (97−65=3297-65=3297−65=32). This consistent difference means that if a character is represented in 8 bits, simply changing the bit that corresponds to the value 32 (the 252^525 position) from 0 to 1 (for uppercase to lowercase) or 1 to 0 (for lowercase to uppercase) performs the case conversion efficiently.

  30. 30

    What is Unicode, and why was it developed as a 'superset' of ASCII?

    Model answer

    Unicode is a modern character encoding standard that uses more bits than ASCII to represent characters from all human languages, past, present, and future, including emojis, making it a superset.

    Explanation

    ASCII's 256 character limit was insufficient for global communication. Unicode was developed to address this by using 16, 24, or even 32 bits per character, allowing for billions of unique characters. This vast capacity accommodates diverse scripts, symbols, and emojis, ensuring universal text compatibility.

  31. 31

    How are emojis represented in computers?

    Model answer

    Emojis are technically characters, represented by specific patterns of zeros and ones (numbers) within the Unicode system, displayed as graphical images.

    Explanation

    Despite appearing as images, emojis are treated by computers as textual characters, similar to letters. Each emoji has a unique Unicode code point, which is a number. Software then uses graphical 'fonts' to render these code points as the familiar colorful images, which can vary slightly across different platforms (Apple, Google, etc.).

  32. 32

    How do computers represent colors like red, green, and blue?

    Model answer

    Computers represent colors as integers, typically by combining three numbers for the intensity of red, green, and blue (RGB), each usually represented by one byte.

    Explanation

    The RGB model is widely used, where each primary color (red, green, blue) is assigned a numerical value, typically from 0 (none) to 255 (maximum intensity). These three numbers, often 8 bits each (a byte), are combined to form a vast spectrum of colors. The total 24 bits (3 bytes) specify one particular color.

  33. 33

    What decimal values for red, green, and blue (RGB) correspond to 'black' and 'white' colors in computer representation?

    Model answer

    Black is represented by RGB values (0, 0, 0) (no red, no green, no blue), while white is represented by RGB values (255, 255, 255) (maximal red, green, and blue).

    Explanation

    In an additive color model like RGB, 0 indicates the complete absence of that color component, and 255 indicates its full intensity. Thus, no color components result in black, and all color components at maximum intensity combine to produce white.

  34. 34

    What are 'pixels' in the context of computer graphics?

    Model answer

    Pixels are the individual dots or squares that collectively compose an image on a digital display.

    Explanation

    A digital image is essentially a grid of tiny picture elements (pixels). Each pixel has its own color, represented by binary data (e.g., RGB values). The density and color of these pixels determine the overall quality and appearance of an image or video.

  35. 35

    How does a computer represent a video?

    Model answer

    A video is represented as a sequence of many individual images (frames) displayed rapidly, typically around 30 images per second, creating the illusion of motion.

    Explanation

    Just like a flip book, video leverages the fact that human eyes perceive continuous motion when a series of still images are presented quickly. Each 'frame' of a video is an image, and videos are essentially a collection of these images played back at a certain frame rate, often along with synchronized audio data.

  36. 36

    How can musical notes be represented in binary for computer storage?

    Model answer

    Musical notes can be represented using numbers that define their frequency (pitch), duration (length), and amplitude (loudness), all of which are ultimately stored as zeros and ones.

    Explanation

    By breaking down the characteristics of sound into quantifiable numerical values, computers can store and reproduce music. Each aspect of a note (how high or low it is, how long it plays, how loud it is) can be assigned a numerical range, and these numbers are then converted into binary.

  37. 37

    How does a computer distinguish between the number 65 and the letter 'A' if both are stored as binary patterns representing 65?

    Model answer

    The distinction is context-dependent; the programmer or software explicitly tells the computer how to interpret the binary pattern, whether as a number, a letter, or a color.

    Explanation

    The raw binary data itself doesn't inherently carry meaning. The software (e.g., a text editor, calculator, or image viewer) determines the interpretation. If a program is designed to display text from a .txt file, it will interpret the binary 65 as 'A'. If it's a calculator, it will treat it as the number 65. The context provided by the program's logic is key.

  38. 38

    What are 'algorithms' in computer science?

    Model answer

    Algorithms are step-by-step instructions for solving some problem, crucial for processing information and transforming input into correct output.

    Explanation

    An algorithm is a precise, unambiguous sequence of steps that, when followed, will reliably solve a particular problem or perform a specific computation. They are the 'secret sauce' within the 'black box' of problem-solving, defining how a computer manipulates data to achieve a desired outcome.

  39. 39

    What are the characteristics of a 'good' algorithm, beyond just being correct?

    Model answer

    Beyond correctness, a good algorithm is efficient, meaning it solves a problem quickly using minimal computing resources like CPU, RAM, and time.

    Explanation

    While getting the right answer is essential, how that answer is achieved is equally important. An efficient algorithm is one that scales well with larger inputs, consuming less power, memory, and time, which is critical for real-world applications where resources are often constrained.

  40. 40

    Describe the 'linear search' algorithm for finding a name in a phone book.

    Model answer

    A linear search involves starting at the beginning of the phone book and examining each page sequentially until the desired name is found.

    Explanation

    This is a straightforward but often inefficient algorithm. If there are 'N' pages, in the worst case (the name is at the end or not present), it requires checking 'N' pages. Its time complexity is linear, meaning the time taken increases proportionally with the size of the problem.

  41. 41

    Why is the linear search algorithm considered 'slow' for a large phone book?

    Model answer

    It's slow because in the worst case, one might have to check every single page, resulting in a large number of steps proportional to the size of the book.

    Explanation

    If a phone book has 1000 pages, finding a name at the very end would require 1000 page turns. This direct relationship between problem size (N) and time taken (N steps) makes it inefficient for large datasets, especially if the search is performed repeatedly.

  42. 42

    Describe the 'binary search' algorithm for finding a name in a phone book.

    Model answer

    A binary search involves opening the phone book roughly in the middle, determining which half contains the desired name, and then repeatedly dividing the remaining half in two until the name is found.

    Explanation

    This algorithm requires the data to be sorted (like an alphabetized phone book). By repeatedly halving the search space, it eliminates a large portion of possibilities with each step. This makes it significantly more efficient than linear search for large datasets.

  43. 43

    How does the 'binary search' algorithm compare in efficiency to a linear search?

    Model answer

    Binary search is significantly more efficient than linear search, especially for large problems, exhibiting logarithmic time complexity (log base 2 of N) compared to linear search's linear complexity (N).

    Explanation

    If a problem size (N) doubles, a linear search takes twice as long. A binary search, however, only requires one additional step. For a 1000-page book, a binary search might find a name in about 10 steps (log2(1000)≈10log_2(1000) \approx 10log2​(1000)≈10), whereas a linear search could take up to 1000 steps. This dramatic difference in growth rate is why binary search is preferred for sorted data.

  44. 44

    What is 'pseudo code'?

    Model answer

    Pseudo code is an English-like or human-readable, terse formulation of step-by-step instructions for an algorithm, not tied to any formal programming language.

    Explanation

    It's a high-level description of an algorithm's logic, using a mixture of natural language and programming-like constructs (like 'if,' 'then,' 'loop'). Pseudo code helps programmers plan and communicate algorithms without getting bogged down in the specific syntax of a particular programming language.

  45. 45

    In the pseudo code for the phone book search, why is it important to include a condition for when the person is not in the book?

    Model answer

    It's crucial to include a 'not found' condition to prevent the algorithm from endlessly searching or crashing (hanging) if the desired entry doesn't exist, ensuring well-defined behavior.

    Explanation

    Anticipating 'corner cases' like an item not being present is vital in programming. Without an explicit exit condition, an algorithm might enter an infinite loop, consuming all resources, or trigger an undefined behavior, leading to software freezes or crashes. Good code handles all possible scenarios gracefully.

  46. 46

    What are 'functions' in programming?

    Model answer

    Functions are verbs or actions in a program that perform a small, specific piece of work or functionality.

    Explanation

    Functions (also called methods or subroutines) encapsulate a set of instructions that can be reused. They allow programmers to break down complex problems into smaller, manageable tasks. For example, a 'print' function performs the action of displaying text on the screen.

  47. 47

    What are 'conditionals' in programming, and what are 'Boolean expressions'?

    Model answer

    Conditionals (like 'if' statements) are forks in the road that allow a program to make decisions. Boolean expressions are questions that evaluate to a 'yes' or 'no' (true or false) answer, guiding those decisions.

    Explanation

    Conditionals control the flow of a program, executing different blocks of code based on whether a condition is met. A Boolean expression, named after George Boole, is the test performed by a conditional. For instance, 'Is X greater than 5?' is a Boolean expression, returning true or false, which then directs the program's path.

  48. 48

    What are 'loops' in programming?

    Model answer

    Loops are programming constructs that induce cyclical behavior, allowing a set of instructions to be repeated again and again.

    Explanation

    Loops are essential for tasks that involve repetition, such as iterating over a list of items or performing an action multiple times. They save programmers from writing the same code repeatedly and are controlled by a condition that determines when the looping should stop.

  49. 49

    What is the principle of 'abstraction' in computing, and why is it important?

    Model answer

    Abstraction is the principle of hiding complex lower-level implementation details and providing a simpler, higher-level interface. It's important because it allows programmers to build upon existing solutions without needing to understand every underlying mechanism.

    Explanation

    Instead of working directly with zeros and ones, programmers use high-level languages and tools. Abstraction means that someone else has already solved the hard problems (e.g., how to make a computer 'print'). These solutions are then packaged into easier-to-use functions or APIs. This enables rapid development and allows programmers to focus on their specific problem rather than reinventing basic functionalities.

  50. 50

    What is 'Scratch' and what type of programming language is it?

    Model answer

    Scratch is a graphical programming language designed for beginners, developed by MIT's Media Lab, that uses drag-and-drop puzzle pieces to create programs.

    Explanation

    It's a visual block-based language that simplifies the process of coding by replacing text-based syntax with interlocking graphical blocks. This makes it highly intuitive for learning foundational programming concepts like functions, loops, and conditionals, especially for younger learners.

  51. 51

    What is the purpose of the 'green flag' and 'red stop sign' in Scratch?

    Model answer

    The green flag initiates (starts) a Scratch program, while the red stop sign halts (stops) its execution.

    Explanation

    These visual cues are standard in the Scratch environment. Clicking the green flag is analogous to running a script, causing all blocks connected to a 'when green flag clicked' event to begin. The red stop sign serves as an emergency stop, immediately terminating all running scripts.

  52. 52

    What is an 'argument' or 'input' to a function in programming, as demonstrated by the 'say' block in Scratch?

    Model answer

    An argument is a piece of information provided to a function that influences its behavior. In Scratch's 'say' block, the editable white oval is an argument, determining what text the sprite will display.

    Explanation

    Functions often need specific data to perform their task. For the 'say' function, the text to be spoken is its input. Different arguments will lead to different outputs or side effects from the same function, making functions flexible and reusable.

  53. 53

    What is a 'side effect' in a computer program?

    Model answer

    A side effect is something that happens visibly on the screen or audibly from a speaker as a result of a function being executed, such as a speech bubble appearing.

    Explanation

    Side effects are observable changes to the program's state or the user interface, not just a return value. In the Scratch 'say' block, the actual appearance of the speech bubble on the stage is the visual side effect of the function call.

  54. 54

    What is a 'return value' from a function, contrasting it with a side effect?

    Model answer

    A return value is data that a function computes and hands back internally to the program, which the human may not immediately see. A side effect is a visible or audible change to the program's environment.

    Explanation

    The 'ask' block in Scratch provides a good example. While it might display a prompt (a side effect), its primary purpose is to capture user input and return that input as a value (stored in the 'answer' variable) for the program to use. The user doesn't see the 'return value' directly; they see the prompt and type their answer.

  55. 55

    What is a 'variable' in programming, and what can it store?

    Model answer

    A variable is a named storage location, similar to X, Y, or Z in math, that can hold different types of values, not just numbers, such as human names or strings of text.

    Explanation

    Variables are fundamental for storing and manipulating data in a program. They allow data to be referred to by a meaningful name, making the code more readable and flexible. The value stored in a variable can change during program execution.

  56. 56

    Why is it generally bad practice to copy and paste (duplicate) code or puzzle pieces in programming?

    Model answer

    Duplicating code leads to 'bad design' because if a change is needed, it must be updated in multiple places, increasing the chance of errors and making maintenance difficult.

    Explanation

    This principle is known as 'Don't Repeat Yourself' (DRY). When code is duplicated, any modification or bug fix must be applied to every copy. This is prone to human error and makes the program harder to manage. Factoring out common logic into a single function or loop is a better approach.

  57. 57

    How can one improve the design of code that repeats similar actions multiple times, like a cat meowing thrice?

    Model answer

    The design can be improved by using a 'loop' (like Scratch's 'repeat' block) to perform the action multiple times, centralizing the logic and making it easier to modify.

    Explanation

    Instead of writing 'play sound meow; wait; play sound meow; wait; play sound meow; wait;', a loop allows you to write 'repeat 3 times: { play sound meow; wait; }'. This makes the code shorter, clearer, and much easier to change if, for example, the number of meows or the waiting time needs to be adjusted.

  58. 58

    How can custom 'blocks' or functions be created in Scratch to abstract away details?

    Model answer

    Custom blocks can be created using the 'Make a Block' feature, allowing programmers to define a new puzzle piece that encapsulates a sequence of actions or other blocks, abstracting its implementation details.

    Explanation

    Creating a custom block (e.g., 'meow N times') turns a complex sequence into a single, reusable block. Once defined, other parts of the program can simply call this new block without needing to know the specific steps it performs, promoting modularity and abstraction.

  59. 59

    In the 'petting a cat' example, why did the program fail when the 'forever' block was omitted?

    Model answer

    Without the 'forever' block, the program checked if the mouse was touching the cat only once at the very beginning. If the mouse wasn't touching it then, the condition would never be re-evaluated later.

    Explanation

    The computer executes instructions incredibly fast. If the 'if touching mouse pointer' block wasn't inside a loop, it would run its check instantly at the program's start. If the mouse wasn't over the cat at that exact moment, the condition would be false, and the program would immediately finish, never checking again for mouse contact.

  60. 60

    What is a 'sprite' in Scratch, and how can its appearance be changed?

    Model answer

    A sprite is an object in Scratch, often a character or item, that can be programmed to move and interact. Its appearance can be changed by switching its 'costume' to different pre-designed or custom images.

    Explanation

    Sprites are the active elements in a Scratch project. They can have multiple costumes, which are different images. By rapidly switching between these costumes, programmers can create the illusion of animation, as demonstrated with the trash can lid opening and Oscar the Grouch appearing.

  61. 61

    In the 'Oscar time' game, how was the animation of the trash can lid opening implemented?

    Model answer

    The trash can animation was implemented by giving the trash can sprite multiple 'costumes' (images) representing different states of the lid (closed, open) and switching between them.

    Explanation

    This is a basic animation technique. Instead of a complex motion sequence, the illusion of the lid opening is created by displaying one costume (closed lid), and then, when triggered (e.g., by mouse hover), switching to another costume (open lid). The speed of switching determines how smooth the animation appears.

  62. 62

    How was the illusion of multiple falling trash items created in the 'Oscar time' game using only one trash sprite?

    Model answer

    The illusion of multiple falling trash items was created by 'teleporting' the single trash sprite back to a random sky location (Y=180) and restarting its downward movement each time it touched Oscar.

    Explanation

    Instead of creating a new sprite for each piece of trash, the program reuses the same sprite. When a piece of trash is 'collected,' it's instantly moved back to the top of the screen at a new random horizontal position, making it appear as if a new piece of trash is falling, efficiently managing resources.

  63. 63

    What is the purpose of the 'set drag mode to draggable' block in Scratch?

    Model answer

    The 'set drag mode to draggable' block allows a user to physically click and drag a sprite on the screen with their mouse.

    Explanation

    By default, sprites might not be movable by the user during game play. This block explicitly enables the interactivity, making it possible for players to control game elements directly with their cursor, as was done to drag the falling trash into Oscar's can.

  64. 64

    How did the 'Harvard Crest' sprite 'feel for walls' in the game, preventing it from going off-screen?

    Model answer

    It 'felt for walls' by checking if it was touching a left or right wall. If so, it would change its X-position by a small amount in the opposite direction, effectively 'bouncing' it off the wall.

    Explanation

    This simple collision detection and response mechanism prevents the sprite from disappearing beyond the screen boundaries. If the crest hits the right wall, changing X by -1 nudges it back left by one pixel, creating the effect of being blocked or bouncing off.

  65. 65

    How was the autonomous bouncing movement of the 'Yale' sprite implemented in the game?

    Model answer

    The 'Yale' sprite's autonomous movement was implemented with a 'forever' loop that consistently moved it 'one step'. If it touched a wall, it would 'turn around 180 degrees' to reverse its direction.

    Explanation

    This creates a continuous back-and-forth motion. The 'move one step' block ensures constant motion. The conditional check for wall contact, combined with the 'turn 180 degrees' block, provides the bounce logic, making the sprite appear to ricochet off the boundaries.

  66. 66

    How was the 'MIT' sprite programmed to follow the 'Harvard' sprite, creating a 'boss level' challenge?

    Model answer

    The 'MIT' sprite was programmed with a 'forever' loop to 'point towards' the Harvard sprite and then 'move one step', causing it to continuously track and pursue Harvard.

    Explanation

    This demonstrates a simple AI behavior: pursuit. By consistently reorienting itself to face the target ('point towards') and then moving forward, the MIT sprite effectively 'homes in' on the Harvard sprite's current position, making it a dynamic and challenging obstacle for the player.

1 of 66
Question 1 of 66

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent