Mettl Fundamental Coding Skills 5 — Questions and Answers
Question 1: What is the output of: `print(2 ** 3)` in Python?
- 6
- 9
- 5
- 8 (Correct answer)
Correct answer: 8
The `**` operator in Python is the exponentiation operator, so `2 ** 3` equals 2³ = 8.
Question 2: Which of the following is a valid way to comment out a single line in Python?
- // This is a comment
- /* This is a comment */
- # This is a comment (Correct answer)
- -- This is a comment
Correct answer: # This is a comment
Python uses the `#` character to start a single-line comment; everything after `#` on that line is ignored.
Question 3: What is a stack overflow error typically caused by?
- Accessing an array out of bounds
- Unbounded recursion filling the call stack (Correct answer)
- Using too much heap memory
- Declaring too many global variables
Correct answer: Unbounded recursion filling the call stack
A stack overflow occurs when recursive function calls accumulate without hitting a base case, exhausting the call stack's memory.
Question 4: Which of the following best describes a 'variable scope'?
- The data type of a variable
- The region of code where a variable can be accessed (Correct answer)
- The memory size of a variable
- The default value of a variable
Correct answer: The region of code where a variable can be accessed
Scope defines the region of the program where a variable is visible and can be referenced.
Question 5: What does DRY stand for in software development?
- Dynamic Runtime Yield
- Don't Repeat Yourself (Correct answer)
- Data Retrieval Yield
- Direct Reference Yield
Correct answer: Don't Repeat Yourself
DRY (Don't Repeat Yourself) is a principle that encourages reducing code duplication by abstracting repeated logic.
Question 6: In a for loop `for (int i = 0; i < 5; i++)`, how many times does the loop body execute?
- 4
- 6
- 5 (Correct answer)
- 1
Correct answer: 5
The loop runs for i = 0, 1, 2, 3, 4 (stopping when i reaches 5), so the body executes exactly 5 times.
Question 7: What is the primary purpose of version control systems like Git?
- To compile code faster
- To track changes to code over time and enable collaboration (Correct answer)
- To automatically fix bugs in code
- To deploy applications to servers
Correct answer: To track changes to code over time and enable collaboration
Version control systems track the history of code changes, allow branching, and enable multiple developers to collaborate safely.
What is the output of: `print(2 ** 3)` in Python?