Syntax Error Detection
Which line in the following Python code causes a syntax error? nnn1. for i in range(5):n2. print(i)n3. print('Done')nnSelect the problematic line.
- Line 1
- Line 2
- Line 3
- All lines are correct
- None of the abvoe
Logical Error Identification
What is the main issue with this code if the goal is to sum all numbers from 1 to 5? nnntotal = 0nfor i in range(1, 5):n total += innWhich is the correct revision?
- Change range(1, 5) to range(1, 6)
- Change total = 0 to total = 1
- Replace += with =+
- Remove total = 0
- Use range(0, 5) instead
Variable Name Typo
What will happen when the following code is executed?nnncount = 10nprint(cout)n
- A NameError will occur
- cout will print as 'cout'
- 10 will be printed
- The program runs but prints nothing
- SyntaxError will be rased
Index Out of Range
Given the list `nums = [2, 4, 6, 8]`, what happens if you run `print(nums[4])`?
- An IndexError is raised
- It prints 8
- It prints 2
- It prints None
- It prints 'nums[4]'
Indentation Error
Which change will fix the following Python code?nnndef greet():nprint('Hello!')n
- Indent the print statement
- Add parentheses to 'def greet:'
- Change 'def' to 'function'
- Remove the colon from line 1
- Capitalize 'print'
Infinite Loop Debugging
What is the main bug in this code?nnni = 0nwhile i u003C 3:n print(i)n
- i is never incremented, causing an infinite loop
- i starts at 1 instead of 0
- Indentation is missing
- Print statement should be outisde the loop
- The colon is not needed after while
Print Statement Fix
What is wrong with this code in Python 3?nnnprint 'Hello World!'n
- Parentheses are missing in print()
- Single quotes are not allowed
- print should be Print
- Hello World should be in double quotes
- There is a comma missing at the end
Type Error Identification
What error occurs when running this code?nnnx = '10' + 2n
- TypeError
- ValueError
- KeyError
- SyntaxError
- No error, output is '102'
Off-by-One Error
In the following code, what will be printed?nnnfor i in range(3):n print(i)n
- 0, 1, 2
- 1, 2, 3
- 0, 1, 2, 3
- 1, 2
- 3, 2, 1
Function Return Bug
Consider this code:nnndef multiply(x, y):n result = x * ynprint(multiply(2, 4))nnWhat does it print?
- None
- 8
- Error: multiply is not defined
- 2, 4
- multiply(2, 4)