Identifying and Correcting Errors - AP Computer Science Principles

  1. What is the result of '3 ** 2' in Python?
    Result: 9. Double asterisk performs exponentiation in Python.
  2. What is the binary representation of the decimal number 10?
    Binary: 1010. Convert decimal to binary using powers of 2.
  3. What is the correct syntax for defining a function in Python?
    def function_name(parameters):. Standard function definition syntax in Python.
  4. What is the ASCII value for the character 'A'?
    ASCII: 65. Standard ASCII value for uppercase A character.
  5. Which Python keyword is used to handle exceptions?
    try. Used with except to catch and handle errors.
  6. What is the purpose of 'break' in a loop?
    Exits the loop prematurely. Immediately terminates loop execution and continues after loop.
  7. Identify the error in 'if x > 5 then y = 10;' in Python.
    Remove 'then': 'if x > 5: y = 10'. Python doesn't use 'then' keyword in if statements.
  8. What is the correct syntax for a for-loop in Python?
    for i in range(n):. Standard Python loop syntax iterating from 0 to n-1.
  9. What is the error in 'if (x > y) print('x is greater');' in Python?
    Use a colon: 'if (x > y): print('x is greater');'. Python if statements require colon after condition.
  10. What operator is used to check equality in Python?
    ==. Double equals tests equality, single equals assigns values.
  11. What is the hexadecimal representation of the decimal number 15?
    Hexadecimal: F. 15 in decimal equals F in hexadecimal (base 16).
  12. What is the result of '7 % 2' in Python?
    Result: 1. Modulo operator returns remainder of division operation.
  13. What is the correct method to add an element to a list in Python?
    list.append(element). Standard method to add elements to Python lists.
  14. What is the value of 10 mod 310 \bmod 3?
    Value: 1. Modulo operation returns remainder after division.
  15. What is the output of 'print(2 ** 3)' in Python?
    Output: 8. Double asterisk is the exponentiation operator in Python.
  16. Find the error in 'while x = 5: pass' in Python.
    Correct: 'while x == 5: pass'. Single equals is assignment, double equals is comparison.
  17. What is the decimal equivalent of the binary number 1101?
    Decimal: 13. Binary 1101 = 8+4+1=138 + 4 + 1 = 13 in decimal.
  18. What is the purpose of the 'return' statement in a function?
    Returns a value from a function. Exits function and sends value back to caller.
  19. Find the error in 'while (x = 10): pass' in Python.
    Use '==' for comparison: 'while (x == 10): pass'. Assignment operator used instead of equality comparison.
  20. Find the error in 'print 5 + 5' in Python 3.
    Use parentheses: 'print(5 + 5)'. Python 3 requires parentheses for print function calls.
  21. What is the output of '10 / 3' in Python 3?
    Output: 3.3333... Python 3 performs true division by default.
  22. What is the correct way to start a comment in Python?
    #. Hash symbol starts single-line comments in Python.

Study these flashcards