Identifying and Correcting Errors - AP Computer Science Principles
- What is the result of '3 ** 2' in Python?
- Result: 9. Double asterisk performs exponentiation in Python.
- What is the binary representation of the decimal number 10?
- Binary: 1010. Convert decimal to binary using powers of 2.
- What is the correct syntax for defining a function in Python?
- def function_name(parameters):. Standard function definition syntax in Python.
- What is the ASCII value for the character 'A'?
- ASCII: 65. Standard ASCII value for uppercase A character.
- Which Python keyword is used to handle exceptions?
- try. Used with except to catch and handle errors.
- What is the purpose of 'break' in a loop?
- Exits the loop prematurely. Immediately terminates loop execution and continues after loop.
- 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.
- 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.
- 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.
- What operator is used to check equality in Python?
- ==. Double equals tests equality, single equals assigns values.
- What is the hexadecimal representation of the decimal number 15?
- Hexadecimal: F. 15 in decimal equals F in hexadecimal (base 16).
- What is the result of '7 % 2' in Python?
- Result: 1. Modulo operator returns remainder of division operation.
- 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.
- What is the value of ?
- Value: 1. Modulo operation returns remainder after division.
- What is the output of 'print(2 ** 3)' in Python?
- Output: 8. Double asterisk is the exponentiation operator in Python.
- Find the error in 'while x = 5: pass' in Python.
- Correct: 'while x == 5: pass'. Single equals is assignment, double equals is comparison.
- What is the decimal equivalent of the binary number 1101?
- Decimal: 13. Binary 1101 = in decimal.
- 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.
- Find the error in 'while (x = 10): pass' in Python.
- Use '==' for comparison: 'while (x == 10): pass'. Assignment operator used instead of equality comparison.
- Find the error in 'print 5 + 5' in Python 3.
- Use parentheses: 'print(5 + 5)'. Python 3 requires parentheses for print function calls.
- What is the output of '10 / 3' in Python 3?
- Output: 3.3333... Python 3 performs true division by default.
- What is the correct way to start a comment in Python?
- #. Hash symbol starts single-line comments in Python.