Certainly! Below is a quiz similar to your original format with multiple-choice questions, programming snippets, and error identification.
Quiz: Programming and Error Finding
Time: 40 mins Marks: 20
Name:__________________ ID:__________________
- In Git, which command will create a new branch named "feature-branch"?
a)
git new branch feature-branch
b) git branch feature-branch
c) git checkout -b feature-branch
d) git init feature-branch
- In Python, which exception is commonly raised for operating system-related errors?
a)
ValueError
b) OSError
c) IndexError
d) KeyError
- Consider the following Python code snippet. What error will it produce? 1 point
def greet():
print(Hello, World!")
greet()
a) IndentationError
b) SyntaxError
c) NameError
d) TypeError
- Which Python library is used for creating plots and charts?
a)
json
b) math
c) matplotlib
d) pandas
- The following code snippet is meant to calculate the factorial of a number using recursion. Find the error. 1 point
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n)
print(factorial(5))
a) SyntaxError
b) RecursionError
c) ValueError
d) TypeError
- What will be the output of the following Python code? 2 points
try:
print(5/0)
except ZeroDivisionError:
print("Cannot divide by zero")
except Exception as e:
print(e)
else:
print("No exceptions occurred.")
a) "Cannot divide by zero"
b) An unhandled exception is raised
c) "No exceptions occurred."
d) "ZeroDivisionError"
- Which line in this bash script will cause an error? 1.5 points
#!/bin/bash
for i in {1..5}
do
echo Number is $i
done
missing_done_statement
a) Line 1
b) Line 2
c) Line 4
d) Line 6
- Analyze the code below and provide the correct output. 1.5 points
import numpy as np
array = np.array([1, 2, 3, 4, 5])
incremented_array = array + 10
print(incremented_array)
a) [11, 12, 13, 14, 15]
b) [10, 10, 10, 10, 10]
c) [1, 2, 3, 4, 5, 10]
d) A TypeError is raised
Answers:
- b)
git branch feature-branch
- b)
OSError
- b) SyntaxError (missing opening quote in the print statement)
- c)
matplotlib
- b) RecursionError (the recursion has no base case to stop calling itself)
- a) "Cannot divide by zero"
- d) Line 6 (there is no command
missing_done_statement and the do block is not closed correctly)
- a)
[11, 12, 13, 14, 15] (NumPy array operation adds 10 to each element)
Instructions for scoring: Mark each correct answer with the corresponding points. Total the score at the end of the quiz. The maximum possible score is 20 points.