Using Programs with Data - AP Computer Science Principles

  1. What does 'break' do in a loop?
    Exits the loop immediately. Break statement terminates loop execution completely.
  2. Identify the error in 'for i in 5: print(i)'
    'range()' is needed to iterate through integers. Cannot iterate directly over integer; range creates sequence.
  3. Which data structure uses key-value pairs?
    Dictionary. Dictionaries map unique keys to corresponding values.
  4. What is a string in programming?
    A sequence of characters. Text data type enclosed in quotes or apostrophes.
  5. Identify the correct syntax for a Python function call.
    function_name(arguments). Parentheses after name pass values to function parameters.
  6. Choose the correct syntax to declare an integer variable in Python.
    variable_name = 0. Python uses assignment operator to create variables dynamically.
  7. What does 'len()' function return?
    The number of items in an object. Built-in function counts elements in sequences and collections.
  8. What is the purpose of 'continue' in a loop?
    Skips the current iteration and continues with the next. Continue jumps to next iteration without finishing current one.
  9. Identify the error in the expression: 5+′3′5 + '3'
    Type error: mixing integer and string. Cannot add integer and string directly without type conversion.
  10. Identify the error: 'if x = 10:'
    Use '==' for comparison, not '='. Assignment operator should be comparison operator for conditions.
  11. State the syntax to access the third element of a list in Python.
    list_name[2]. List indexing starts at 0, so third element is index 2.
  12. Identify the error in this function definition: 'def add(a, b): return a + b'
    No error; the function is correct. This function definition follows proper Python syntax rules.
  13. Identify the error in this loop: 'for i in range(5) print(i)'
    Missing colon after range(5). Python requires colon after for statement header.
  14. What is the purpose of the 'if' statement in programming?
    To execute code conditionally based on a boolean expression. It evaluates the boolean and runs code only when true.
  15. What is an 'else' clause used for?
    To execute code when an 'if' condition is false. Else provides alternative code path for false conditions.
  16. What is the result of 3//23 // 2 in Python?
    1. Floor division operator returns integer quotient without remainder.
  17. Which data type is used for true/false values?
    Boolean. Boolean data type represents logical values: True or False.
  18. Which keyword defines a function in Python?
    'def'. Keyword that declares new function definitions in Python.
  19. What does the 'return' statement do in a function?
    It exits the function and optionally returns a value. Return sends a value back to the caller and stops execution.
  20. Which data type would you use for a decimal number in Python?
    Float. Float type handles numbers with decimal points.
  21. What is the main difference between a list and a tuple?
    Lists are mutable; tuples are immutable. Lists can be modified; tuples cannot be changed.
  22. What type is returned by 'input()' function in Python?
    String. Input always returns text even for numeric entries.
  23. What is the syntax for a for-each loop in Python?
    for item in iterable:. Standard Python loop syntax for iterating collections.
  24. What is the purpose of a function in programming?
    To encapsulate code for reuse and organization. Functions group code into reusable blocks with optional parameters.
  25. Which keyword is used to start a loop in Python?
    'for' or 'while'. Both keywords create repetitive execution structures in Python.
  26. What function converts a string to an integer in Python?
    'int()'. Built-in function converts string numbers to integer type.
  27. What is the purpose of a 'for' loop?
    To iterate over a sequence of items. For loops process each item in collections automatically.
  28. What does the 'append' method do to a list?
    Adds an element to the end of the list. Append method inserts new item at list's final position.
  29. Choose the correct way to start a multiline comment in Python.
    Use triple quotes: '''comment'''. Triple quotes allow comments spanning multiple lines.
  30. What is the value of 232^3?
    8. Two raised to the third power equals eight.
  31. What is the output of 'print("Hello, World!")'?
    Hello, World. Print function displays text exactly as written inside quotes.
  32. How is a comment started in Python?
    Using '#'. Hash symbol creates single-line comments in Python code.
  33. Which operator is used for exponentiation in Python?
    '**'. Double asterisk performs mathematical power operations.
  34. Identify the error: 'list.append(x)' when 'list' is not defined.
    'list' must be defined before use. Variable name must exist before calling methods on it.
  35. What is a variable in programming?
    A named storage location for data. Variables hold values that can be accessed and modified by name.
  36. What is an array?
    A collection of elements identified by index. Arrays store multiple values accessible by numeric position.
  37. Identify the component of a loop that determines when it stops.
    Loop condition or termination condition. This boolean expression controls when the loop continues or stops.
  38. What is the result of 4×(3+2)4 \times (3 + 2)?
    20. Order of operations: parentheses first, then multiplication.
  39. What is a 'while' loop used for?
    To repeat code while a condition is true. While loops continue until condition becomes false.

Study these flashcards