Tag Archives: quiz

Computer Vision Quiz-5

Q1. For a multi-channel input feature map, we apply Max-pooling independently on each channel and then concatenate the results along the channel axis?

  1. True
  2. False

Answer: 1
Explanation: Max-pooling operation is applied independently on each channel and then the results are concatenated along the channel axis to form the final output. Refer to this beautiful explanation by Andrew Ng to understand more.

Q2. A fully convolutional network can take as input the image of any size?

  1. True
  2. False

Answer: 1
Explanation: Because a fully convolutional network doesnot contain any fully connected or Dense layer, this can take as input the image of any size.

Q3. In R-CNN, the bounding box loss is only calculated for positive samples (samples that contains classes present in the dataset)?

  1. True
  2. False

Answer: 1
Explanation: In R-CNN, the bounding box loss is only calculated for positive samples (samples that contains classes present in the dataset) as it makes no sense to fine-tune a bounding box that doesn’t contain object.

Q4. In the VGG16 model, we have all the Conv layers with same padding and filter size and the downsampling is done by MaxPooling only?

  1. True
  2. False

Answer: 1
Explanation: Earlier models like AlexNet use large filter size in the beginning and downsampling was done either by max-pooling or by convolution. But in the VGG16 model, we have all the Conv layers with same padding and filter size and the downsampling is done by MaxPooling only. So what have we gained by using, for instance, a stack of three 3×3 conv. layers instead of a single 7×7 layer? First, we incorporate three non-linear rectification layers instead of a single one, which makes the decision function more discriminative. Second, we decrease the number of parameters. Refer to the Section 2.3 of this research paper to understand more.

Q5. 1×1 convolution can also help in decreasing the computation cost of a convolution operation?

  1. True
  2. False

Answer: 1
Explanation: 1×1 convolution can also help in decreasing the computation cost of a convolution operation. Refer to this beautiful explanation by Andrew Ng to understand more.

Q6. Can we use Fully Convolutional Neural Networks for object detection?

  1. Yes
  2. No

Answer: 1
Explanation: Yes a Fully Convolutional Neural Networks can be used for object detection. For instance, YOLO etc.

Q7. Which of the following networks can be used for object detection?

  1. Overfeat
  2. Faster RCNN
  3. YOLO
  4. All of the above

Answer: 4
Explanation: All of the above mentioned networks can be used for object detection. For instance, Faster RCNN belongs to Region based methods whereas YOLO, Overfeat belongs to sliding window based methods.

Q8. AlexNet was one of the first networks that uses ReLU activation function in the hidden layers instead of tanh/sigmoid (which were quite common at that time)?

  1. True
  2. False

Answer: 1
Explanation: This was one of the revolutionary ideas that boomed deep learning i.e. using ReLU activation function in the hidden layers instead of tanh/sigmoid (which were quite common at that time).

Computer Vision Quiz-4

Q1. The values in a filter/mask are called as

  1. Coefficients
  2. Weights
  3. Both of the above
  4. None of the above

Answer: 3
Explanation: The values in a filter/mask are called as either coefficients or weights.

Q2. Which of the following networks uses the idea of Depthwise Separable Convolutions?

  1. AlexNet
  2. MobileNet
  3. ResNet
  4. VGG16

Answer: 2
Explanation: As mentioned in the MobileNet paper, MobileNets are based on a streamlined architecture that uses depthwise separable convolutions to build light weight deep neural networks that work even in low compute environment, such as a mobile phones. Refer to this research paper to understand more.

Q3. What is the output of a Region Proposal Network (RPN) at each sliding window location if we have k anchor boxes?

  1. 2k scores and 4k bounding box coordinates
  2. 4k scores and 2k bounding box coordinates
  3. k scores and 4k bounding box coordinates
  4. 4k scores and 4k bounding box coordinates

Answer: 1
Explanation: In a Region Proposal Network (RPN), for k anchor boxes we get 2k scores (that estimate probability of object or not) and 4k bounding box coordinates corresponding to each sliding window location. Refer to Figure 3 of this research paper to understand more.

Q4. Which of the following networks uses Skip-connections?

  1. DenseNet
  2. ResNet
  3. U-Net
  4. All of the above

Answer: 4
Explanation: All of the above mentioned networks uses Skip-connections.

Q5. For binary classification, we generally use ________ activation function in the output layer?

  1. Tanh
  2. ReLU
  3. Sigmoid
  4. Leaky ReLU

Answer: 3
Explanation: For binary classification, we want the output (y) to be either 0 or 1. Because sigmoid outputs the P(y=1|x) and has value between 0 and 1, so it is appropriate for binary classification.

Q6. In ResNet’s Skip-connection, the output from the previous layer is ________ to the layer ahead?

  1. added
  2. concatenated
  3. convoluted
  4. multiplied

Answer: 1
Explanation: In ResNet’s Skip-connection, the output from the previous layer is added to the layer ahead. Refer to the Figure 2 of this research paper to understand more.

Q7. In Fast R-CNN, we extract feature maps from the input image only once as compared to R-CNN where we extract feature maps from each region proposal separately?

  1. True
  2. False

Answer: 1
Explanation: Earlier in R-CNN we were extracting features from each region proposals separately using a CNN and this was very time consuming. So, to counter this, in Fast R-CNN we extract feature maps from the input image only once and then project the region proposals onto this feature map. This saves a lot of time. Refer to this link to understand more.

Q8. For Multiclass classification, we generally use ________ activation function in the output layer?

  1. Tanh
  2. ReLU
  3. Sigmoid
  4. Softmax

Answer: 4
Explanation: For Multiclass classification, we generally use softmax activation function in the output layer. Refer to this beautiful explanation by Andrew Ng to understand more.

Computer Vision Quiz-3

Q1. Which of the following object detection networks uses a ROI Pooling layer?

  1. R-CNN
  2. Fast R-CNN
  3. YOLO
  4. All of the above

Answer: 2
Explanation: Out of the above mentioned networks, only Fast R-CNN uses a ROI Pooling layer. Becuase of this, Fast R-CNN can take any size image as input as compared to R-CNN where we need to resize region proposals before passing into CNN. Refer to this research paper to understand more.

Q2. Which of the following techniques can be used to reduce the number of channels/feature maps?

  1. Pooling
  2. Padding
  3. 1×1 convolution
  4. Batch Normalization

Answer: 3
Explanation: 1×1 convolution can be used to reduce the number of channels/feature maps. Refer to this beautiful explanation by Andrew Ng to understand more.

Q3. Which of the following networks has the fastest prediction time?

  1. R-CNN
  2. Fast R-CNN
  3. Faster R-CNN

Answer: 3
Explanation: As clear from the name, Faster R-CNN has the fastest prediction time. Refer to this research paper to understand more.

Q4. Max-Pooling makes the Convolutional Neural Network translation invariant (for small translations of the input)?

  1. True
  2. False

Answer: 1
Explanation: According to Ian Goodfellow, Max pooling achieves partial invariance to small translations because the max of a region depends only on the single largest element. If a small translation doesn’t bring in a new largest element at the edge of the pooling region and also doesn’t remove the largest element by taking it outside the pooling region, then the max doesn’t change.

Q5. What do you mean by the term “Region Proposals” as used in the R-CNN paper?

  1. regions of an image that could possibly contain an object of interest
  2. regions of an image that could possibly contain information other than the object of interest
  3. final bounding boxes given by the R-CNN

Answer: 1
Explanation: As clear from the name, Region Proposals are a set of candidate regions that could possibly contain an object of interest. These region proposals are then fed to a CNN which extracts features from each of these proposals and these features are then fed to a SVM classifier to determine what type of object (if any) is contained within the proposal. The main reason behind extracting these region proposals beforehand is that instead of searching the object at all image locations, we should search for only those locations where there is a possibility of object. This will reduce the false positives as we are only searching in the regions where there is a possibility of having an object. Refer to this research paper to understand more.

Q6. Because Pooling layer has no parameters, they don’t affect the gradient calculation during backpropagation?

  1. True
  2. False

Answer: 2
Explanation: It is true that Pooling layer has no parameters and hence no learning takes place during backpropagation. But it’s wrong to say that they don’t affect the gradient calculation during backpropagation because pooling layer guides the gradient to the right input from which the Pooling output came from. Refer to this link to know more.

Q7. Which of the following techniques was used by Traditional computer vision object detection algorithms to locate objects in images at varying scales and locations?

  1. image pyramids for varing scale and sliding windows for varing locations
  2. image pyramids for varing locations and sliding windows for varing scale

Answer: 1
Explanation: Becuase an object can be of any size and can be present at any location, so for object detection we need to search both at different locations and scales. As we know that by using image pyramids (multi-resolution representations for images) we can handle scale dependency and for locations we can use sliding window. So, traditional computer vision algorithms use these for object detection. For instance, refer to the Overfeat paper that shows how a multiscale and sliding window approach can be efficiently implemented within a ConvNet.

Q8. How do you introduce non-linearity in a Convolutional Neural Network (CNN)?

  1. Using ReLU
  2. Using a Max-Pooling layer
  3. Both of the above
  4. None of the above

Answer: 3
Explanation: Non-linearity can be introduced by either using ReLU (non-linear activation function) or by using a Max-Pooling layer (as max is a non-linear function).

Computer Vision Quiz-2

Q1. Suppose we have an image of size 4×4 and we apply the Max-pooling with a filter of size 2×2 and a stide of 2. The resulting image will be of size:

  1. 2×2
  2. 2×3
  3. 3×3
  4. 2×4

Answer: 1
Explanation: Because in Max-pooling, we take the maximum value for each filter location so the output image size will be 2×2 (the number of filter locations). Refer to this beautiful explanation by Andrew Ng to understand more.

Q2. In Faster R-CNN, which loss function is used in the bounding box regressor?

  1. L2 Loss
  2. Smooth L1 Loss
  3. Log Loss
  4. Huber Loss

Answer: 2
Explanation: In Faster R-CNN, Smooth L1 loss is used in the bounding box regressor. This is a robust L1 loss that is less sensitive to outliers than the L2 loss used in R-CNN and SPPnet. Refer to Section 3.1.2 of this research paper to understand more.

Q3. For binary classification, we generally use ________ loss function?

  1. Binary crossentropy
  2. mean squared error
  3. mean absolute error
  4. ctc

Answer: 1
Explanation: For binary classification, we generally use Binary crossentropy loss function. Refer to this beautiful explanation by Andrew Ng to understand more.

Q4. How do we perform the convolution operation in computer vision?

  1. we multiply the filter weights with the corresponding image pixels, and then sum these up
  2. we multiply the filter weights with the corresponding image pixels, and then subtract these up
  3. we add the filter weights and the corresponding image pixels, and then multiply these up
  4. we add the filter weights with the corresponding image pixels, and then sum these up

Answer: 1
Explanation: In Convolution, we multiply the filter weights with the corresponding image pixels, and then sum these up.

Q5. In a Region Proposal Network (RPN), what is used in the last layer for calculating the objectness scores at each sliding window position?

  1. Softmax
  2. Linear SVM
  3. ReLU
  4. Sigmoid

Answer: 1
Explanation: In a Region Proposal Network (RPN), the authors of Faster R-CNN paper uses a 2 class softmax layer for calculating the objectness scores for each proposal at each sliding window position.

Q6. In R-CNN, the regression model outputs the actual absolute coordinates of the bounding boxes?

  1. Yes
  2. No

Answer: 2
Explanation: In R-CNN, the regression model outputs the deltas or the relative coordinate change of the bounding boxes instead of absolute coordinates. Refer to Appendix C of this research paper to understand more.

Q7. Is Dropout a form of Regularization?

  1. Yes
  2. No

Answer: 1
Explanation: Dropout, applied to a layer, consists of randomly dropping out(setting to zero) a number of output features of the layer during training. Because as any node can become zero, we can’t rely on any one feature so have to spread out the weights similar to regularization.

Q8. A fully convolutional network can be used for

  1. Image Segmentation
  2. Object Detection
  3. Image Classification
  4. All of the above

Answer: 4
Explanation: We can use a fully convolutional network for all of the above mentioned tasks. For instance, for image segmentation we have U-Net, for object detection we have YOLO etc.

Computer Vision Quiz-1

Q1. Which of the following is not a good evaluation metric for Multi-label classification?

  1. Mean Average Precision at K
  2. Hamming Score
  3. Accuracy
  4. Top k categorical accuracy

Answer: 3
Explanation: Accuracy is not a good evaluation metric for Multi-label classification. As we know in multi-label each example can be assigned to multiple classes so let’s say if the predicted output was [0, 0, 0, 0, 1, 1,0] and the correct output was [1, 1, 0, 0, 0, 0, 0], my accuracy would still be 3/6 but it should be 0 as it is not able to predict any of the classes correctly.

Q2. Which of the following are the hyperparameters for a Pooling layer?

  1. filter size
  2. stride
  3. which type of Pooling to use (max or average)
  4. All of the above

Answer: 4
Explanation: All of the above mentioned are the hyperparameters for a Pooling layer.

Q3. Images are an example of ________ data?

  1. Structured
  2. Unstructured

Answer: 2
Explanation: Structured data refers to the type of data where each feature has a well defined meaning and opposite is true for unstructured data. So, images are an example of unstructured data.

Q4. For image classification, MaxPooling tends to works better than average pooling?

  1. Yes
  2. No

Answer: 1
Explanation: Because in image classification our main aim is to identify whether a feature is present or not so MaxPooling tends to works better than average pooling.

Q5. What is Pointwise Convolution?

  1. 1×1 convolution
  2. Strided Convolution
  3. convolution followed by MaxPool
  4. convolution followed by Dropout

Answer: 1
Explanation: According to the MobileNet paper, “After depthwise convolution, The pointwise convolution then applies a 1×1 convolution to combine the outputs of the depthwise convolution.”. Refer to Section 3.1 of this research paper to understand more.

Q6. What is a Region Proposal network?

  1. a fully convolutional network that simultaneously predicts object bounds and objectness scores at each position
  2. a fully connected network that simultaneously predicts object bounds and objectness scores at each position
  3. a fully convolutional network that predicts only the objectness scores at each position
  4. a fully connected network that predicts only the object bounds at each position

Answer: 1
Explanation: According to the Faster R-CNN paper, Region Proposal network (RPN) is a fully convolutional network that takes an image(of any size) as input and outputs a set of rectangular object proposals, each with an objectness score. Refer to Section 3.1 of this research paper to understand more.

Q7. In MobileNetv2, the Depthwise Separable Convolutions are replaced by _________ ?

  1. Normal Convolution
  2. Strided Convolution
  3. Bottleneck Residual Block (Inverted Residuals and Linear Bottleneck)
  4. Residual Blocks

Answer: 3
Explanation: In MobileNetv2, the Depthwise Separable Convolutions are replaced by Bottleneck Residual Block (Inverted Residuals and Linear Bottleneck). Refer to Table 1 of this research paper to understand more.

Q8. Can we use Convolutional Neural Networks for image classification?

  1. Yes
  2. No

Answer: 1
Explanation: Generally, Convolutional Neural Networks are preferred for any image related tasks such as image classification, object detection etc.

Machine Learning Quiz-1

Q1. Let say if you have 10 million dataset, and it would take 2 week time to train your model. Which of the following statement do you most agree with?

  1. If you have already trained a model with different dataset and is performing well with 98% dev accuracy on that dataset, you just use that model instead of training on current dataset for two weeks
  2. If 10 million dataset is enough to build a good model, you might be better off training with just 1 million dataset to gain 10 times improvement in how quickly you can run experiments, even if each model performs a bit worse because it’s trained on less data
  3. You will go with complete dataset and run the model for two weeks to see the first results
  4. All of the above

Answer: 2
Explanation: In Machine learning, the best approach is to build an initial model quickly using a random subset of data and then use the Bias/Variance analysis and error analysis to priortize next steps.

Q2. In a Multi-layer Perceptron (MLP), each node is connected to all the previous layer nodes?

  1. True
  2. False

Answer: 1
Explanation: Since a Multi-Layer Perceptron (MLP) is a Fully Connected Network, each node in one layer connects with a certain weight to every node in the following layer.

Q3. Identify the following activation function : g(z) = (exp(z) – exp(-z))/(exp(z) + exp(–z))?

  1. Tanh activation function
  2. Sigmoid activation function
  3. ReLU activation function
  4. Leaky ReLU activation function

Answer: 1
Explanation: This refers to Tanh activation function. Similar to sigmoid, the tanh function is continuous and differentiable at all points, the only difference is that it is symmetric around the origin. Refer to this beautiful explanation by Andrew Ng to know more.

Q4. Suppose we have a neural network having 10 nodes in the input layer, 5 nodes in the hidden layer and 1 node in the output layer. What will be the dimension of W1 (first layer weights) and W2 (second layer weights)?

  1. W1:5×1, W2:1×1
  2. W1:1×10, W2:1×5
  3. W1:1×5, W2:5×10
  4. W1:5×10, W2:1×5

Answer: 4
Explanation: Generally, the weights dimensions for a layer is (next layer nodes x previous layer nodes) so the answer is W1:5×10, W2:1×5. Refer to this beautiful explanation by Andrew Ng to know more.

Q5. In Dropout, What will happen if we increasing the Dropout rate from (say) 0.5 to 0.8?

  1. Reducing the regularization effect.
  2. Causing the neural network to end up with a lower training set error.
  3. Both of the above.
  4. None of the above.

Answer: 3
Explanation:

Q6. Finding good hyperparameter values is very time-consuming. So typically you should do it once at the start of the project, and try to find very good hyperparameters so that you don’t ever have to revisit tuning them again.

  1. True
  2. False

Answer: 2
Explanation: You can’t really know beforehand which set of hyperparameters will work best for your case. You need to follow the iterative process of Idea->Code->Eperiment.

Q7. In a deep neural network, what is the general rule for the dimensions of weights and biases of layer l? Where n is the number of units in layer l.

  1. w[l] : (n[l], n[l])
    b[l] : (n[l], 1)
  2. w[l] : (n[l+1], n[l])
    b[l] : (n[l-1], 1)
  3. w[l] : (n[l], n[l-1])
    b[l] : (n[l], 1)
  4. w[l] : (n[l], n[l-1])
    b[l] : (n[l-1], 1)

Answer: 3
Explanation: The dimensions of weights of layer l is given by (n[l], n[l-1]) and biases is given by (n[l], 1). Refer to this beautiful explanation by Andrew Ng to know more.

Q8. Which of the following method can be used for hyperparameter tuning?

  1. Random Search
  2. Grid Search
  3. Bayesian optimization
  4. All of the above.

Answer: 4
Explanation: All of the above methods can be used for hyperparameter tuning.

Python Quiz-10

Q1. What will be the output of the following code:

  1. 8
  2. 9
  3. 10
  4. Error!

Answer: 2
Explanation: In Python language, len() function gives the length of an object. When the object is a string, it will output the number characters in the string.

Q2. What will be the output of following code:

  1. 5
  2. 6
  3. 5.14
  4. 7

Answer: 2
Explanation: => print(func3(2))
=> return math.ceil(func1(2)+func2(2))
=> return math.ceil(2*2+math.sqrt(2))
=> return math.ceil(4+1.414)
=> return math.ceil(5.414)
=> return 6
=> 6

Q3. What will be the output of following code:

  1. {‘a’: 1, ‘b’: 2, ‘c’: 3}
  2. {‘c’: 3}
  3. {‘a’: 1, ‘b’: 2}
  4. TypeError

Answer: 4
Explanation: D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple. But in this question only one argument is given to popitem() method.

Q4. Which of the following statements is not true?

  1. We can change the value of a private variable of superclass in the subclass
  2. Superclass non-private method can be overridden.
  3. The constructor of a class in invoked automatically.
  4. A derived class is a subclass of superclass

Answer: 1
Explanation: We can not change the value of a private variable of superclass in the subclass.

Q5. What type of error will be raised when the imported module is not found?

  1. ImportError
  2. NullPointerError
  3. NameError
  4. IndexNotFoundError

Answer: 1
Explanation: ImportError will be raised when the imported module is not found.

Q6. How does Python treat a string literal when it is not assigned to any variable?

  1. It will ignore the string literal.
  2. It will automatically assings a variable to it.
  3. It will through an error.
  4. None of the above.

Answer: 1
Explanation: In Python language, if you do not assign a string literal to a variable, it will ignore the string literal while in other languages like Java it will throw a compile time error.

Q7. In Python, which of the following variable is not of a integer data type?

  1. x = 435757438
  2. x = 5
  3. x = 23.45
  4. x = -5

Answer: 3
Explanation: Int is a whole number, it can be either positive or negative. It can not have decimal values also it can be of unlimited length.

Q8. Which of the following statement will extract the percentage of the mentioned student?

  1. print(data[‘school’][‘student’][‘result’][‘percentage’])
  2. print(data[‘School’][‘student’][‘result’][‘percentage’])
  3. print(data[‘School’][‘student’][‘result’][0])
  4. print(data[‘Sschool’][‘student’][0][‘percentage’])

Answer: 2
Explanation: json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary.
json.loads() in Python
=> print(data[‘School’][‘student’][‘result’][‘percentage’])
=> 70%

Python Quiz-9

Q1. Which of the following statements is true?

  1. Special method __add()__ is called when + operator is used.
  2. In Python, same operator may behave differently depending upon operands.
  3. __init__() function is called when a new object is instantiated.
  4. All of the above

Answer: 4
Explanation: All of the given three options are correct.

Q2. In Python, which of the following statement will print a random number between 1 and 10 (both 1 and 10 included)?

  1. print(random.randrange(1, 10))
  2. print(random.random(1, 10))
  3. print(random.randint(1, 10))
  4. None of the above.

Answer: 3
Explanation: 1. print(random.randrange(1, 10)) -> This will print a random integer between 1 and 10 where 10 is not included.
2. print(random.random(1, 10)) -> This will throw an error because random does not take any argument but two are given.
3. print(random.randint(1, 10)) -> This will print a random number between 1 and 10 (both 1 and 10 included).

Q3. Which of the following is not true of global variable in Python?

  1. global keyword can be used to create a global variable inside a local scope.
  2. Accessible only in the block they are defined in.
  3. A variable created in the main body of the Python code is a global variable.
  4. Accessible from anywhere in the script.

Answer: 2
Explanation: Global variables are available from within any scope, either it is global or local.

Q4. If x = 2**4/2+3-1, then what will be the data type of x?

  1. int
  2. float

Answer: 2
Explanation: Division operator is used in x = 2**4/2+3-1 and division operator gives the value including the decimals which will be of float data type.

Q5. Which of the following method can be used to combine strings and numbers?

  1. concatenate()
  2. join()
  3. append()
  4. format()

Answer: 4
Explanation: The format() method format the passed arguments and places them in the string according to the placeholders {}.
Fancier Output Formatting

Q6. Suppose x = 6.3, then which of the following statement will throw an error?

  1. y = float(x)
  2. y = int(x)
  3. y = complex(x)
  4. None of the above.

Answer: 4
Explanation: int, float and complex are numeric data types. These will cast ‘x’ into it’s respective data types.

Q7. What will be the output of print(ord(‘the’))?

  1. 116 104 101
  2. 116 116 116
  3. 104 104 104
  4. TypeError

Answer: 4
Explanation: Python ord() function returns the Unicode code from a given character. This function accepts a string of unit length as an argument and returns the Unicode equivalence of the passed argument.
Reference: ord() function in Python

Q8. In Python, which of the following character is used to add at the start of a line to make it a comment?

  1. #
  2. //
  3. &

Answer: 1
Explanation: In Python language comments start with # and the rest of the line will be rendered as comment.

Python Quiz-8

Q1. What will be the output of following code:

  1. [7, 9, 2, 0, 2, 1]
  2. [‘7’, ‘9’, ‘2’, ‘0’, ‘2’, ‘1’]
  3. [7, 2, 0, 2, 1]
  4. Runtime error!

Answer: 2
Explanation: This is an example of list comprehension in Python. List comprehensions are used for creating new lists from other iterables like tuples, strings, arrays, lists, etc. A list comprehension consists of brackets containing the expression, which is executed for each element along with the for loop to iterate over each element.
List Comprehensions

Q2. What are the name of the operators |, &, >> and << respectively?

  1. AND, OR, RIGHT SHIFT and LEFT SHIFT
  2. AND, OR, LEFT SHIFT and RIGHT SHIFT
  3. OR, AND, LEFT SHIFT and RIGHT SHIFT
  4. OR, AND, RIGHT SHIFT and LEFT SHIFT

Answer: 4
Explanation: OR, AND, RIGHT SHIFT and LEFT SHIFT are name of the |, &, >> and << operators respectively.

Q3. What will be the output of following code:/code/

  1. [1, 2] [1, 2, 3, 4]
  2. [1, 2, 3, 4] [1, 2, 3, 4]
  3. [1, 2, 3, 4] [1, 2]
  4. [1, 2] [3, 4]

Answer: 2
Explanation: In Python language, assigning one variable to another variable creates an alias of each variable. Here variable b is an alias of variable a. It means both variable a and b points to the same object in the memory. That’s why when you are updating the value of variable b, value of variable a is also changing.

Q4. Python is an object oriented programming language.

  1. True
  2. False

Answer: 1
Explanation: Python is an object oriented programming language. Almost everything in Python is an object. A class in Python is a blueprint for creating objects.

Q5. What will be the output of following code:

  1. 1 2 (3, 4, 5)
  2. 1 2 3
  3. 1 2 [3, 4, 5]
  4. ValueError

Answer: 3
Explanation: *variable is basically extended iterable unpacking. It will assign a list of all items not assigned to a regular variable name. So from tuple “num”, 1 is assinged to a, 2 is assigned to b and rest all items will be assigend as list to c.
Extended Iterable Unpacking

Q6. Which of the following statement is the correct way of assigning an integer value to a variable in Python?

  1. x = ‘6’
  2. int x = 6;
  3. x = 6
  4. Integer x = 6;

Answer: 3
Explanation: x = ‘6’ -> will create a string data type.
int x = 6; and Integer x = 6; -> It is a way of assignment and declaration in Java language.

In Python there is no need to declare the data type using int or Integer. It will create a variable with respect to the type of data you assing to it.

Q7. What is the syntax for multiline comment in Python?

  1. Use /* at the start of the first line and use */ at the end of the last line.
  2. Use <-- at the start of the first line and use --> at the end of the last line.
  3. Python does not have syntax for multiline comment. You can either use # at the start of every line or make it as multiline string (triple quote).
  4. None of the above.

Answer: 3
Explanation: Since Python does not have syntax for multiline comments, there is a workaround. As Python ignores the string literal if it is not assigned to a variable, we can add multiline string in our code and place the multiline comment inside it.

Q8. What will be the output of following code:

  1. 1 2 3
  2. 1 2 3 4
  3. 1 2 3 5
  4. 1 2 3 4 5

Answer: 1
Explanation: while loop executes the block until a condition is satisfied. When the condition becomes false, the statement immediately after the loop is executed. The else clause is only executed when your while condition becomes false. If you break out of the loop, or if an exception is raised, it won’t be executed.
Reference: While Loop

Python Quiz-7

Q1. if x = [1, 2, 5, 3, 4], what will be the output of print(x[0:3:2])?

  1. [1, 5, 4]
  2. [1, 5]
  3. [1, 2, 5, 3, 4]
  4. List index out of range exception!

Answer: 2
Explanation: Slice in Python list here refer to list[::]. So x[0:3:2] will start at index 0, stop at index 3 at take a step of 2.

Q2. What is the difference between a method and a function in Python?

  1. Functions can be called only by its name but methods can not be called by its name only.
  2. we don’t need a class to define a function but methods are defined inside a class.
  3. Functions are independent entities in a program while methods are dependent on the class they belong to.
  4. All of the above.

Answer: 4
Explanation: All the given three options are correct.

Q3. What will be the output of following code:

  1. [20, 30, 40, 50]
  2. [10, 20, 30, 40, 10]

Answer: 2
Explanation: In Python language, + operator append the elements to the original array.

Q4. What will be the output of following code:

  1. 3 2
  2. 2 2
  3. 2 3
  4. SyntaxError

Answer: 4
Explanation: It will raise an error. In function definition, non-default arguments should be written before the default arguments.

Q5. Which of the following is true when you open a file using with keyword?

  1. File reading and writing are faster using the with statement.
  2. The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
  3. You need not to handle exception anymore in the whole script.

Answer: 2
Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.

Q6. A class can serve as base class for many derived classes.

  1. True
  2. False

Answer: 1
Explanation: yes a class can serve as base class for many derived classes. It is also call as Hierarchical inheritance.

Q7. The following code will throw an error.

  1. True
  2. False

Answer: 1
Explanation: **kwargs are used as arbitrary keyword arguments. If we do not know how many keyword arguments that will be passed into our function then we can add two asterisk ** before the parameter name in the function definition. In the given function definition x will be a dictinary of arguments. That’s why print(x[a]) will raise an error.

Q8. Which of the following statement will create a variable of string type?

  1. a = ”’AILearner”’
  2. a = “AILearner”
  3. a = ‘AILearner’
  4. All of the above.

Answer: 4
Explanation: In Python language, a string can be created by using any of the single, double or triple quotation marks. Usually three quotes are used to create a multiline string.