Python for Data Science NPTEL Week 2 Assignment Answers
Are you looking for the Python for Data Science NPTEL Week 2 Assignment Answers 2024? You’ve come to the right place! This guide offers detailed solutions to the Week 2 assignment questions, helping you solidify your understanding of Python programming and its applications in data science.
Course Link: Click Here
Table of Contents
Python for Data Science Nptel Week 2 Assignment Answers (JULY-DEC 2024)
Q1. Which of the following object does not support indexing?
tuple
list
dictionary
set
Answer: set
Q2. Given a NumPy array, arr = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]), what is the output of the command, print(arr[0][1])?
[[1 2 3]
[4 5 6]
[7 8 9]]
[1 2 3]
[4 5 6]
[7 8 9]
Answer: [4 5 6]
For answers or latest updates join our telegram channel: Click here to join
These are Python for Data Science Nptel Week 2 Assignment Answers
Q3. What is the output of the following code?
[2, 3, 4, 5]
[0 1 2 3]
[1, 2, 3, 4]
Will throw an error: Set objects are not iterable.
Answer:[1, 2, 3, 4]
Q4. What is the output of the following code?
import numpy as np
arr = np.array (np.arange(0, 15))
print(arr.reshape (3,5))
Answer: c)
For answers or latest updates join our telegram channel: Click here to join
These are Python for Data Science Nptel Week 2 Assignment Answers
Q5. Which of the following code gives output My friend’s house is in Chennai?
Answer: a),d)
Q6. Let t1 = (1, 2, “tuple”, 4) and t2 = (5, 6, 7). Which of the following will not give any error after the execution?
a) t1.append(5)
b) x=t2[t1[1]]
c) t3=t1+t2
d) t3=(t1,t2)
e) t3=(list(t1),list(t2))
Answer: b),c),d),e)
For answers or latest updates join our telegram channel: Click here to join
These are Python for Data Science Nptel Week 2 Assignment Answers
Q7. Let d= {1 : “Pyhton”, 2 : [1, 2, 3]}. Which among the following will not give the error after the execution?
a) d[2].append(4)
b) x=d[0]
c) d[“one”]=1
d) d.update(‘one′:2)
Answer: a),c),d)
Q8. Which of the following data type is immutable?
list
set
tuple
dictionary
Answer: tuple
For answers or latest updates join our telegram channel: Click here to join
These are Python for Data Science Nptel Week 2 Assignment Answers
Q9. student = {‘name’: ‘Jane’, ‘age’: 25, ‘courses’: [‘Math’, ‘Statistics’]}
Which among the following will return
{‘name’: ‘Jane’, ‘age’: 26, ‘courses’: [‘Math’, ‘Statistics’], ‘phone’: ‘123-456’}
a) student.update({‘age’ : 26})
b) student.update({‘age’ : 26, ‘phone’: ‘123-456’})
c) student[‘phone’] = ‘123-456’
d) student.update({‘age’ : 26})
e) None of the above
Answer: b),c)
Q10.What is the output of the following code?
[‘M’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
[‘m’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
[‘M’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
[‘m’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
Answer: [‘M’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
For answers or latest updates join our telegram channel: Click here to join
These are Python for Data Science Nptel Week 2 Assignment Answers
Python for Data Science NPTEL All weeks: Click Here
More Nptel Courses: https://progiez.com/nptel-assignment-answers
Python for Data Science NPTEL Week 2 Assignment Answers (JAN-APR 2024)
Course name: Python For Data Science
Course Link: Click Here
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Python for Data Science Assignment 2 Answers
Q1. Which of the following object does not support indexing?
tuple
list
dictionary
set
Answer: set
Q2. Given a NumPy array, arr = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]), what is the output of the command, print(arr[0][1])?
a. [[1 2 3]
[4 5 6]
[7 8 9]
b. [1 2 3]
c. [4 5 6]
d. [7 8 9]
Answer: c. [4 5 6]
Q3. What is the output of the following code?
[2, 3, 4, 5]
[0 1 2 3]
[1, 2, 3, 4]
Will throw an error: Set objects are not iterable.
Answer: [1, 2, 3, 4]
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Python for Data Science Assignment 2 Answers
Q4. What is the output of the following code?
a)
b)
c)
d)
Answer: c) [[0 1 2 3 4 [ 5 6 7 8 9] [10 11 12 13 14]]
Q5. Which of the following code gives output My friend’s house is in Chennai?
a)
b)
c)
d)
Answer: a), d)
a) place = ‘Chennai’
print (“My friend’s house is in {}”. format (place) )
d) print (“My friend’s house is in {}”. format (“Chennai”) )
Q6. Let t1=(1,2,“tuple”,4) and t2=(5,6,7). Which of the following will not give any error after the execution?
t1.append(5)
x=t2[t1[1]]
t3=t1+t2
t3=(t1,t2)
t3=(list(t1), list(t2))
Answer: b, c, d, e
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Python for Data Science Assignment 2 Answers
Q7. Let d={1:“Pyhton”,2:[1,2,3]}. Which among the following will not give the error after the execution?
d[2].append(4)
x=d[0]
d[“one”]=1
d.update({‘one’ : 2})
Answer: a, c, d
Q8. Which of the following data type is immutable?
list
set
tuple
dictionary
Answer: tuple
Q9. student = {‘name’: ‘Jane’, ‘age’: 25, ‘courses’: [‘Math’, ‘Statistics’]}
Which among the following will return
{‘name’: ‘Jane’, ‘age’: 26, ‘courses’: [‘Math’, ‘Statistics’], ‘phone’: ‘123-456’}?
a. student.update({‘age’ : 26})
b. student.update({‘age’ : 26, ‘phone’: ‘123-456’})
c. student[‘phone’] = ‘123-456’
student.update({‘age’ : 26})
d. None of the above
Answer: a, b, c
Q10. What is the output of the following code?
[‘M’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
[‘m’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
[‘M’, ‘a’, ‘h’, ‘e’, ‘s’, ‘h’]
[‘m’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
Answer: [‘M’, ‘A’, ‘H’, ‘E’, ‘S’, ‘H’]
For answers or latest updates join our telegram channel: Click here to join
These are NPTEL Python for Data Science Assignment 2 Answers
More Weeks of Python for Data Science: Click here
More Nptel Courses: Click here
Python for Data Science NPTEL Week 2 Assignment Answers (JAN-APR 2023)
Course Name: Python for Data Science
Course Link: Click Here
These are NPTEL Python for Data Science Assignment 2 Answers
Q1. What will be the output of the following:
a. [[2 6 10]
[4 8 12]]
b. [[2 4 6]
[8 10 12]]
c. [[2 4]
[6 8]
[10 12]]
d. [[2 8]
[4 10]
[6 12]]
Answer: b. [[2 4 6]
[8 10 12]]
Q2. Let t1 = (1, 2, “tuple”, 4) and t2 = (5, 6, 7). Which of the following will not give any error after the execution?
a. t1.append(5)
b. x = t2[t1[1]]
c. t3 = t1 + t2
d. t3 = (t1, t2)
e. t3 = (list(t1), list(t2))
Answer: a, b, c, d, e
These are NPTEL Python for Data Science Assignment 2 Answers
Q3. Let d1 = {1 : “Pyhton”, 2 : [1, 2, 3]}. Which among the following will not give the error after the execution?
a. d1[2].append(4)
b. x = d1[0]
c. d1[“one”] = 1
d. d1.update({‘one’ : 2})
Answer: a, c, d
Q4. S1 = {1, 2, 3}
S2 = {5, 6, 3}
S1.add(4)
S2.add(“4”)
What will be the output of S1 − S2?
a. {1, 2, 3}
b. {1, 2, 3, 4}
c. {1, 2, “4”}
d. {1, 2, 4}
Answer: d. {1, 2, 4}
These are NPTEL Python for Data Science Assignment 2 Answers
Q5. S1 = “Hello” and S2 = “World”. Which of the following will not return “Hello world”?
a. S1 + “ ” + S2
b. S1[0 :] + “ ” + S2[0 :]
c. “{} {}”.format(S1, S2)
d. S1[: −1] + “ ” + S2[: −1]
Answer: d. S1[: −1] + “ ” + S2[: −1]
Q6. Given a NumPy array, arr = np.array([[1, 9, 10], [3, 7, 6], [12, 8, 0]]), find the correct command from the following options to get an output array as [16 24 16]?
a. arr[1: 2]
b. np.sum(arr, axis = 0)
c. np.sum(arr, axis = 1)
d. np.sum([[1, 9, 10], [3, 7, 6], [12, 8, 0]])
Answer: b. np.sum(arr, axis = 0)
These are NPTEL Python for Data Science Assignment 2 Answers
Q7. mat = np.matrix(“5, 9, 10; 2, 5, 4; 1, 9, 8; 2, 6, 8”)
mat1 = np.matrix(“1, 2, 3, 4”)
mat2 = np.insert(mat, 1, mat1, axis= 1)
print(mat2)
What will be the output of the above command?
a. [[5 2 1 2]
[1 2 3 4]
[9 5 9 6]]
[10 4 8 8]]
b. [[1 2 3 4]
[5 2 1 2]
[9 5 9 6]]
[10 4 8 8]]
c. [[5 1 9 10]
[2 2 5 4]
[1 3 9 8]]
[2 4 6 8]]
d. It will give an error.
Answer: d. It will give an error.
Q8. student = {‘name’: ‘Jane’, ‘age’: 25, ‘courses’: [‘Math’, ‘Statistics’]}
Which among the following will return
{‘name’: ‘Jane’, ‘age’: 26, ‘courses’: [‘Math’, ‘Statistics’], ‘phone’: ‘123-456’}
a. student.update({‘age’ : 26})
b. student.update({‘age’ : 26, ‘phone’: ‘123-456’})
c. student[‘phone’] = ‘123-456’
d. student.update({‘age’ : 26})
e. None of the above
Answer: b, c
These are NPTEL Python for Data Science Assignment 2 Answers
Q9. c = np.arange(start = 1, stop = 20, step = 3). What is c[5]?
a. 13
b. 16
c. 15
d. 12
Answer: b. 16
Q10. Which of the following data type is immutable?
a. list
b. set
c. tuple
d. dictionary
Answer: c. tuple
These are NPTEL Python for Data Science Assignment 2 Answers
More Weeks of Python for Data Science NPTEL: Click here
More NPTEL courses: https://progiez.com/nptel
Python for Data Science NPTEL Week 2 Assignment Answers (JULY-DEC 2022)
Q1. Which of the following function(s) can be used to resize a NumPy array in Python from the given options.
a. array.shape(reshape)
b. array.reshape(shape)
c. numpy.reshape(array, shape)
d. numpy.reshape(shape, array)
Answers: b, c
These are NPTEL Python for Data Science Assignment 2 Answers
2. Create the tuples given below:
tuple_1 = (1,5,6,7,8)
tuple_2 = (8,9,4)
Identify which of the following options does not work on the given tuples
a. sum(tuple_1)
b. len(tuple_2)
c. tuple_2 + tuple_1
d. tuple_1[3] = 45
Answers: d. tuple_1[3] = 45
3. Create a sequence of numbers from 15 to 25 and increment by 4. What is the index of the element 19?
a. 3
b. 2
c. 0
d. 1
Answers: d. 1
These are NPTEL Python for Data Science Assignment 2 Answers
4. Consider a variable job = “chemist”. Which of the following expression(s) will retrieve the last character from the string?
a. job[7]
b. job[len(job) – 1]
c. job[5:6]
d. job[- 1]
Answers: b, c
5. Given a list, ls = [1, 2, 3, 3, 2, 3, 1, 4, 5, 6, 5, 6, 3, 2, 1, 1, 1, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 10, 10, 1, 2, 3, 9, 10], which of the following would be the most efficient method in determining the unique elements present in ls?
a. By converting ls into a NumPy array, and applying relevant methods
b. By converting ls into a set
c. By iterating through ls, and doing appropriate manipulations
d. None of the above
Answers: b. By converting ls into a set
These are NPTEL Python for Data Science Assignment 2 Answers
6. Which of the following data structure(s) can be used as a key while creating a dictionary?
a. list
b. str
c. set
d. None
Answers: b. str
7. Given a dictionary, states = {‘Tamil Nadu’: ‘TN’, ‘Karnataka’: ‘KA’, ‘Kerala’: ‘KL’, ‘Maharashtra’: ‘MH’}, which of the following command(s) is used to remove the key-value pair ‘Karnataka’: ‘KA’ from it?
a. del states[‘Karnataka’]
b. states.popitem(‘Karnataka’)
c. states.pop(‘Karnataka’)
d. del states[‘Karnataka’:’KA’]
Answers: c. states.pop(‘Karnataka’)
8. Which of the following is valid to declare a string literal Shin’ichi to a variable?
a. “Shin’ichi”
b. ‘Shin”ichi’‘
c. Shin’ichi’
d. None of the above
Answers: a. “Shin’ichi”
These are NPTEL Python for Data Science Assignment 2 Answers
9. Which of the following commands can be used to create a NumPy array?
a. np.array()
b. np.zeros()
c. np.empty()
d. All of the above
Answers: d. All of the above
10. Given a NumPy array, arr = np.array([[5,9,10], [7,2,6], [12,8,0]]), find the correct command from the following options to get an output array as [24 15 20]?
a. np.sum(arr)
b. np.sum(arr, axis = 0)
c. np.sum(arr, axis = 1)
d. None of the above
Answers: c. np.sum(arr, axis = 1)
These are NPTEL Python for Data Science Assignment 2 Answers