Author Archives: kang & atul

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-5

Q1. The optimizer is an important part of training neural networks. which of the following is not the purpose of using optimizers?

  1. Speed up algorithm convergence
  2. Reduce the difficulty of manual parameter setting
  3. Avoid overfitting
  4. Avoid local extremes

Answer: 3
Explanation: To avoid overfitting, we use regularization and not optimizers.

Q2. Which of the following is not a regularization technique used in machine learning?

  1. L1 regularization
  2. R-square
  3. L2 regularization
  4. Dropout

Answer: 2
Explanation: Of all the above mentioned, R-square is not a regularization technique. R-squared is a statistical measure of how close the data are to the fitted regression line.

Q3. Which of the following are hperparameter in the context of deep learning?

  1. Learning Rate, α
  2. Momentum parameter, β1
  3. Number of units in a layer
  4. All of the above

Answer: 4
Explanation: According to Wikipedia, “In machine learning, a hyperparameter is a parameter whose value is used to control the learning process”. So, all of the above are hyperparameters.

Q4. Which of the following statement is not true with respect to batch normalization?

  1. Batch normalization helps in decreasing training time
  2. Batch normalization add slight regularization effect
  3. After using of batch normalization there is no need to use the dropout
  4. Batch normalization helps in reducing the covariate shift

Answer: 3
Explanation: Although Batch Normalization has a slight regularization effect but this is not why we use this. This is used to make the neural network more robust (reduce covariate shift) and easy to train. While Dropout is used for regularization (reducing overfitting). So, the third option is incorrect.

Q5. In a machine learning project, modelling is an iterative process but deployment is not.

  1. True
  2. False

Answer: 2
Explanation: Deployment is an iterative process, where you should expect to make multiple adjustments (such as metrics monitored using dashboards or percentage of traffic served) to work towards optimizing the system.

Q6. Which of the following activation function works better for hidden layers?

  1. Sigmoid
  2. Tanh

Answer: 2
Explanation: The Tanh activation function usually works better than sigmoid activation function for hidden units because the mean of its output is closer to zero, so it centers the data better for the next layer and the gradients are not restricted to move in a certain direction.

Q7. The softmax function is used to calculate the probability distribution over a discrete variable with n possible values?

  1. True
  2. False

Answer: 1
Explanation: The softmax function is used to calculate the probability distribution over a discrete variable with n possible values. This can be seen as a generalization of the sigmoid function which was used to represent a probability distribution over a binary variable.

Q8. Let say you want to use the transfer learning from task A to task B. Which of the following scenario would support to use this transfer learning?

  1. Task A and B have same input x
  2. You have lot more data for task A than task B
  3. Low level features from task A could be helpful for learning B
  4. All of the above

Answer: 4 Explanation: All of the things mentioned above are pre-requisites for performing transfer learning. Refer to this beautiful explanation by Andrew Ng to know more.

Machine Learning Quiz-4

Q1. Which of the following is an example of unstructured data?

  1. Audio
  2. Images
  3. Text
  4. All of the above

Answer: 4
Explanation: All of these are examples of unstructured data. Refer to this link to know more.

Q2. Which of the following is a model-centric AI development?

  1. Hold the data fixed and iteratively improve the code/model
  2. Hold the code/model fixed and iteratively improve the data

Answer: 1
Explanation: As clear from the name, in model-centric AI development, we hold the data fixed and iteratively improve the code/model

Q3. What is Semi-Supervised Learning?

  1. where for each example we have the correct answer/label and we infer a mapping function from these examples
  2. where for each example we don’t have the correct answer/label and we try to find some sort of structure or pattern in the dataset
  3. where for some examples we have the correct answer/label while for others we don’t have correct answer/label

Answer: 3
Explanation: As clear from the name, in Semi-Supervised learning for some examples we have the correct answer/label while for others we don’t have correct answer/label. Because nowadays we are able to collect huge amount of data and labelling this huge data takes enormous effort so the focus is now shifting to Semi-Supervised learning. This is also known as Self-Supervised learning. Why? Because sometimes the data can be unlabelled but the data itself provides the necessary context which would make up the labels. For instance, CBOW model for creating word embeddings.

Q4. Which of the following is the reason to use non-linear activation function on neural networks?

  1. If you use only linear activation function, then no matter how many layers you use it will be same as not using any hidden layers
  2. Hidden layer with linear activation functions is of no use as it is not adding any non-linearity to the network so the network will not be able to learn complex functions
  3. Adding n number of hidden layers with linear activation function, end up summing it to another linear function
  4. All of the above

Answer: 4
Explanation: All of the above are possible reasons. Refer to this beautiful explanation by Andrew Ng to know more.

Q5. Which of the following activation functions can be used in neural network?

  1. ReLU
  2. Tanh
  3. Sigmoid
  4. All of the above

Answer: 4
Explanation: All of the above activation functions can be used in neural networks. Refer to this beautiful explanation by Andrew Ng to know more.

Q6. RMSprop resolves the limitation of AdaGrad optimizer?

  1. True
  2. False

Answer: 1
Explanation: RMSprop divides the learning rate by exponentially decaying average of squared gradients whereas AdaGrad divides the learning rate by sum of squared gradients. This in turn causes the learning rate to shrink in AdaGrad and eventually become infinitesimally small, at which point the algorithm is no longer able to acquire additional knowledge. Refer to this link to know more.

Q7. If you increase the value of lambda (regularization parameter), then model will always perform better as it helps in reducing the overfitting of model.

  1. True
  2. False

Answer: 2
Explanation: As we increase the regularization hyperparameter lambda, the weights starts becoming smaller. This can also be verified by the weights update equation in gradient descent (with L2 regularization) which is w=w(1-α*λ/m)-α*dLoss/dw. So, as you increase λ to a very high value, weights become closer to 0. This leads to a model that is too simple and ends up underfitting the data thus decreasing the performance of the model. Refer to this beautiful explanation by Andrew Ng to know more.

Q8. What is a multi-task learning in deep learning?

  1. Train n different neural networks to learn n tasks
  2. Train a single neural network to learn n task simultaneously

Answer: 2
Explanation: In multi-task learning, we train a single neural network to learn n task simultaneously. For instance, self driving cars has to detect pedestrains, cars, traffic lights etc.

Machine Learning Quiz-3

Q1. In neural networks, where do we apply batch normalization?

  1. Before applying activation function
  2. After applying activation function

Answer: 1
Explanation: We generally apply batch normalization before applying activation function. Refer to this beautiful explanation by Andrew Ng to know more.

Q2. In Mini-batch gradient descent, if the mini-batch size is set equal to training set size it will become Stochastic gradient descent and if the mini-batch size is set equal to 1 training example it will become batch gradient descent?

  1. True
  2. False

Answer: 2
Explanation: It is actually opposite. In Mini-batch gradient descent, if the mini-batch size is set equal to training set size it will become Batch gradient descent and if the mini-batch size is set equal to 1 training example it will become Stochastic gradient descent.

Q3. If we have enough computation power, it would be wiser to train multiple parallel model and then choose the best one instead of babysitting a single model.

  1. True
  2. False

Answer: 1
Explanation: In deep learning, there is as such no general rule to find the best set of hyperparameters for any task. So, one need to follow the iterative process of Idea -> Code -> Experiment and being able to try out different ideas quickly is more suited instead of babysitting a single model.

Q4. Vectorization allows you to compute forward propagation in an L-layer neural network without an explicit for-loop (or any other explicit iterative loop) over the layers l=1, 2, …,L.?

  1. True
  2. False

Answer: 2
Explanation: We cannot avoid the for-loop iteration over the computations among layers. Refer to this beautiful explanation by Andrew Ng to know more.

Q5. Suppose you ran logistic regression twice, once with regularization parameter λ=0, and once with λ=1. One of the times, you got weight parameters w=[26.29 65.41], and the other time you got w=[2.75 1.32]. However, you forgot which value of λ corresponds to which value of w. Which one do you think corresponds to λ=1?

  1. w=[26.29 65.41]
  2. w=[2.75 1.32]

Answer: 2
Explanation: λ=0 means no regularization is used whereas λ=1 means regularization is used. And as we know that regularization results in weights shrinkage so without regularization you will get larger weights as compared to with regularization.

Q6. What is the value of Sigmoid activation function (let’s denote by g(z)) at an input value of z=0?

  1. 0
  2. 0.5
  3. -♾️
  4. +♾️

Answer: 2
Explanation: As we know that sigmoid is given by g(z) = 1/ (1 + exp(–z)) so at an input value of z=0 this outputs the value of 0.5. Refer to this beautiful explanation by Andrew Ng to know more.

Q7. Suppose you have built a neural network having 1 input, 1 hidden and 1 output layer. You decide to initialize the weights and biases to be zero. Which of the following statements is true?

  1. Each neuron in the hidden layer will perform the same computation in the first iteration. But after one iteration of gradient descent they will learn to compute different things because we have “broken symmetry”.
  2. The hidden layer’s neurons will perform different computations from each other even in the first iteration; their parameters will thus keep evolving in their own way.
  3. Each neuron in the hidden layer will perform the same computation. So even after multiple iterations of gradient descent each neuron in the layer will be computing the same thing as other neurons.

Answer: 3
Explanation: By initializing the weights and biases to 0, Each neuron in the hidden layer will perform the same computation. So even after multiple iterations of gradient descent each neuron in the layer will be computing the same thing as other neurons. Refer to this beautiful explanation by Andrew Ng to know more.

Q8. 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 b1 (first layer bias) and b2 (second layer bias)?

  1. b1:5×1, b2:1×1
  2. b1:1×10, b2:1×5
  3. b1:1×5, b2:5×10
  4. b1:5×10, b2:1×5

Answer: 1
Explanation: Generally, the bias dimensions for a layer is (next layer nodes x 1) so the answer is b1:5×1, b2:1×1. Refer to this beautiful explanation by Andrew Ng to know more.

Machine Learning Quiz-2

Q1. Which of the following is a good choice for image related tasks such as Image classification or object detection?

  1. Multilayer Perceptron (MLP)
  2. Convolutional Neural Network (CNN)
  3. Recurrent Neural Network (RNN)
  4. All of the above

Answer: 2
Explanation: Convolutional Neural Network (CNN) is a good choice for image related tasks such as Image classification or object detection. There are two main reasons for this. First one is Parameter Sharing i.e. a feature detector that is useful in 1 part of image is probably useful in another part of the same image and because of this CNN has less parameters. Second one is Sparsity of connections i.e. in each layer, each output value depends only on small number of inputs (equal to the filter size).

Q2. Which of the following statement is correct?

  1. RMSprop divides the learning rate by an exponentially decaying average of squared gradients
  2. RMSprop divides the learning rate by an exponentially increasing average of squared gradients
  3. RMSprop has a constant learning rate
  4. RMSprop decays the learning rate by a constant value

Answer: 1
Explanation: The weights update equation in RMSprop is given by w=w-α*dw/(Sdw+e)^0.5 where Sdw is an exponentially weighted average (decaying function). Thus, RMSprop divides the learning rate by an exponentially decaying average of squared gradients. Refer to this beautiful explanation by Andrew Ng to know more.

Q3. _____ is a type of gradient descent which processes 1 training example per iteration?

  1. Stochastic Gradient Descent
  2. Batch Gradient Descent
  3. Mini-batch Gradient Descent
  4. None of the above.

Answer: 1
Explanation: Stochastic Gradient Descent processes 1 training example per iteration of gradient descent.

Q4. Let say you have trained a cat classifier on 10 million cat images and it is performing well on live environment. Now in live environment you have encountered new cat species. Due to that your deployed model has started degrading. You have only 1000 images of new indentifed cat species. Which of the following step you should take first?

  1. Put all 1000 images in the training set and start training asap
  2. Try data augmentation on these 1000 images to get more data
  3. Split the 1000 images into train/test set and start the training
  4. Use the data you have to define a new evaluation metric (using a new dev/test set) taking into account the new species, and use that to drive further progress with the model

Answer: 4
Explanation: Because we have a very less amount of data for new cat species (1000) as compared to 10 million so putting these 1000 in training or splitting will not make any difference. Also by augmentation we will not be able to increase the dataset to that extent (10 million). So the only option that left is build a new evaluation metric and penalize the model more for making false predictions on the new species.

Q5. Which of the following is an example of supervised learning?

  1. Given the data of house prices and house sizes, predict house price as a function of house size
  2. Given 50 spam and 50 non-spam emails, predict whether the new email is spam/non-spam
  3. Given the data consisting of 1000 images of cats and dogs each, we need to classify to which class the new image belongs
  4. All of the above

Answer: 4
Explanation: Because for each of the above options, we have the correct answer/label so all of the these are examples of supervised learning.

Q6. Which of the following is True for Structured Data?

  1. Structured Data has clear, definable relationships between the data points, with a pre-defined model containing it
  2. Structured data is quantitative, highly organized, and each of the feature has a well-defined meaning
  3. Structured data is generally contained in relational databases (RDBMS)
  4. All of the above

Answer: 4
Explanation: All of the above is True for Structured Data. Refer to this link to know more.

Q7. You have built a network using the sigmoid activation for all the hidden units. You initialize the weights to relative large values, using np.random.randn(..,..)*10000. What will happen?

  1. This will cause the inputs to the sigmoid to be very large, causing the units to be “highly activated” and thus speed up learning compared to if the weights had to start from small values
  2. It doesn’t matter as long as you initialize the weights randomly gradient descent is not affected by whether the weights are large or small
  3. This will cause the inputs to the sigmoid to be very large, thus causing gradients to also become large. You therefore have to set \alphaα to be very small to prevent divergence; this will slow down learning
  4. This will cause the inputs to the sigmoid to be very large, thus causing gradients to be close to zero and slows down the learning

Answer: 4
Explanation: When we initialize the weights to a very large value, the input to a sigmoid function (that is calculated using z=w*x+b) will also become very large. As we know that for large inputs the sigmoid curve is quite flat and because of this the gradients will be close to 0 and thus slows down the gradient descent or learning.

Q8. Let say you are working on a cat classifier, and have been asked to work on three different metrics. 1. accuracy 2. inference time and 3. memory size. What will you say about the following statement:\n”Having three evaluation metrics will make it easier for you to quickly choose between two different algorithms, and your team can work faster.”

  1. True
  2. False

Answer: 2
Explanation: It is always good to have a single real number evaluation metric. If you have more than 1 evaluation metric then it would be very difficult to access the performance. For instance, if for 1 case if the precision and recall is 60% and 40% while for other case precision and recall is 30% and 70% so it’s very tedious task to judge which one is better. That’s why we have F1 score as it combines precision and recall into one metric.

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.