0% found this document useful (0 votes)
148 views25 pages

Nptel Assessment

The document contains assignment answers for the NPTEL course 'Python for Data Science' across multiple weeks and terms. It includes questions about Python syntax, data types, variable naming, and library usage, along with their correct answers. The content is structured in a question-answer format, covering various programming concepts relevant to Python and data science.

Uploaded by

sboy76385
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views25 pages

Nptel Assessment

The document contains assignment answers for the NPTEL course 'Python for Data Science' across multiple weeks and terms. It includes questions about Python syntax, data types, variable naming, and library usage, along with their correct answers. The content is structured in a question-answer format, covering various programming concepts relevant to Python and data science.

Uploaded by

sboy76385
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

NPTEL ASSESSMENT

PYTHON FOR DATA SCIENCE

Python for Data Science NPTEL Week 1


Assignment Answers (Jul-Dec 2022)

1. What is the output of the following code?


num1 = 12

num2 "58"

print(num1 + num2)

a.12
b.58
c.70

d.Error: Invalid operation, unsupported operator ‘+’ used between ‘int’


and ‘str’ Answer:- d

2. Given two variables j = 6 and g = 3.3. If both normal division and floor
division operators were used to divide j by g, what would be the data type
of the value obtained from the operations?
a. int, int
b. float, float
c. float, int
d. int, float

Answer:- b

3. State whether the given statement is True or False.


When using the floor division operator (//), if the result is
negative, then the result is rounded off to the next largest
integer.

a. True
b. False

Answer:- b

4. Let x = “50”. Which of the following commands converts the ‘x’ to float
datatype?

a. str(float,x)
b. x.float()
c. float(x)
d. Cannot convert a string to float datatype

Answer:- c

5. Which of the following variable names are INVALID in Python?

a. 1_variable
b. variable_1
c. variable_*
d. variable1

Answer:- a, c

6. Which of the following variable assignments would throw an error?

a. var1=True; var2=False;
b. var1=false; var2=true;
c. var1=’True’; var2=’False’;
d. var1=’true’; var2=’false’;

Answer:- b
7. Predict the output of the following code
x=4

y-11

p 5.0

ans=x**(y % p)

print(ans)

a. 4
b. 4.0
c. 5
d. 4.1

Answer:- b

8. The value of the variable result after running the code snippet below is
____
num-20.5

z-3

result-2+:*3+num/lz

print(result)

a. 89.0

b. 17.0

c. 737.0

d. 96.0

Answer:- b
9. Which Python library is commonly used for data wrangling and
manipulation?

a. Numpy
b. Pandas
c. scikit
d. Math

Answer:- b

Python for Data Science NPTEL Week 1


Assignment Answers (Jan-Apr 2023)

Q1. Which of the following is/are the correct ways of naming variables
in Python?
a. 2_max = 5
b. max_2 = 5
c. max2 = 5
d. max @2 = 5

Answer: b, c

Q2. What does 5%11 will evaluate to


a. 1
b. 5
c. 0
d. Syntax error

Answer: b. 5
Q3. What does 4//7 evaluate to
a. 0
b. 1
c. 0.0
d. 4

Answer: a. 0

Q4. What will be the output of the following code snippet?


a. 300
b. 100200
c. ‘100’ + ‘200’
d. ‘100 + 200’

Answer: b. 100200

Q5. What will be the output of the following code snippet?


a. 300
b. 100200
c. ‘100’ + ‘200’
d. ‘100 + 200’

Answer: a. 300

Q6. What is the type of the following expression?


1+4/2
a. int
b. float
c. bool
d. str

Answer: b. float
Q7. What is the type of the following expression?
[1] (1 > 0) and (-1 < 0) and (1 == 1)
a. str
b. bool
c. True
d. False

Answer: c. True

Q8. What is the output of the following code snippet?


a. 32
b. 44
c. 40
d. 36

Answer: c. 40

Q9. Which of the arithmetic operators given below cannot be used


with ‘strings’ in Python?
a. *
b. –
c. +
d. All of the above

Answer: b. –

Q10. Consider the list of instructions and resulting outputs given


below. Pick the set that is incorrect.
a. 4
b. 2
c. 1, 3
d. 1, 3, 4
e. All are correct

Answer: b. 2
Python for Data Science NPTEL Week 1
Assignment Answers (Jul-Dec 2024)

Q1. What is the output of the following code?


36
121212
123
Error: Invalid operation, unsupported operator ‘*’ used between ‘int’ and ‘str’

Answer: 121212

Q2. What is the output of the following code?


-1
-2
-1.28
1.28

Answer: -2

Q3. Consider a following code snippet. What is a data type of y?


int
float
str
Code will throw an error.

Answer: str
Q4. Which of the following variable names are INVALID in Python?
1_variable
variable_1
variable1
variable#

Answer: [A, D] 1_variable, variable#

Q5. While naming the variable, use of any special character other than
underscore(_) ill throw which type of error?
Syntax error
Key error
Value error
Index error

Answer: Syntax error

Q6. Let x = “Mayur”. Which of the following commands converts the


‘x’ to float datatype?
str(float,x)
x.float()
float(x)
Cannot convert a string to float data type

Answer: Cannot convert a string to float data type

Q7. Which Python library is commonly used for data wrangling and
manipulation?
Numpy
Pandas
scikit
Math

Answer: Pandas
Q8. Predict the output of the following code.
12.0
12
11.667
11

Answer: 12

Q9. Given two variables, j = 6 and g = 3.3. If both normal division and
floor division operators were used to divide j by g, what would be the
data type of the value obtained from the operations?
int, int
float, float
float, int
int, float

Answer: float, float

Q10. Let a = 5 (101 in binary) and b = 3 (011 in binary). What is the


result of the following operation?
3
7
5
1

Answer: 1

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

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

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”

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)

Python for Data Science NPTEL Week 2


Assignment Answers (JAN-APR 2024)

Q1. Which of the following object does not support indexing?


tuple
list
dictionary
set

Answer: set

Q2. 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]
Q3. 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

Q4. 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

Q5. 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

Q6. 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’]

Q7. 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

Q8. 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

Q9. 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}
Q10. 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]

Python for Data Science NPTEL Week 3


Assignment Answers (July-Dec2022)

Q1. Choose the appropriate command(s) to filter those booking


details whose reservation_status are a No-show?
a. data_hotel_ns datahotel. loc[data_hotel.reservation_status=’No-Show’]
b. data_hotel_ns = data_hotel[ data _hotel. reservation_status = “No-
Show’]
c. data hotel_ns = data_hotel. reservation_status.loc [data_hotel.isin([‘No-
Show’])]
d. data_hotel_ns = data_hotel.loc [data hotel. reservation_status. isin([ No-
Show’])]

Answer:b, d

Q2. From the same data, find how many bookings were not cancelled
in the year 2017?

a. 9064
b. 6231
c. 9046
d. None of the above

Answer: a. 9064
Q3. From the total bookings that were made in 2017 and not
cancelled, which month had the highest number of repeated guests?
a. July
b. February
c. January
d. None of the above

Answer: c. January

Q4. Which of the following commands can be used to create a


variable Flag, and set the values as Premium when the rating is equal
to or greater than 3.25, and otherwise as Regular?
a. dt_cocoa[°Flag’] = [“Premium” if x 3.25 else “Regular” for x in
dt_cocoa[‘Rating’ ]]
b. dt_cocoa[“Flag’] = [“Premium” if x 3.25 else “Regular” for x in
dt_cocoa[ _` Rating ‘]]
c. dt_cocoa[“Flag”] = np.where(dt_cocoa[ “Rating”] < 3.25, “Regular”,
“Premium”)
d. None of the above

Answer: b, c

Q5. After checking the data summary, which feature requires a data
conversion considering the data values held?
a. Rating
b. Review Date
c. Company
d. None of the above

Answer: b. Review Date


Q6. What is the maximum average rating for the cocoa companies
based out of Guatemala?
a. 43.
b. 53.
c. 42.
d. None of the above

Answer: c. 42.

Q7. Which pandas function is used to stack the dataframes vertically?


a. pd.merge()
b. pd.concat()
c. join()
d. None of the above

Answer: b. pd.concat()

Q8. Of the following set of statements, which of them can be used to


extract the column Direction as a separate dataframe?

a. df_weather[[_`Direction ‘ ]]
b. df_weather.iloc[:,0]
c. df_weather.loc[:.[ ‘Direction ‘]]
d. None of the above

Answer: a, b

Q9. Which one of these students’ average score across all subjects
was the lowest? Which subject has the highest average score across
students?

a. Harini, Maths
b. Sathi, Maths
c. Harini, Physics
d. Rekha, Maths

Answer: b. Sathi, Maths


Python for Data Science NPTEL Week 3
Assignment Answers (Jan-Apr 2023)

Q1. Which of the following is the correct approach to fill missing


values in case of categorical variable?
a. Mean
b. Median
c. Mode
d. None of the above

Answer: c. Mode

Assume a pandas dataframe df_cars which when printed is as shown


below. Based on this information, answer questions 2 and 3.

Q2. Of the following set of statements, which of them can be used to


extract the column Type as a separate dataframe?
a. df cars[[’Type’]]
b. df cars.iloc[[:, 1]
c. df cars.loc[:, [’Type’]]
d. None of the above

Answer: a, c

Q3. The method df_cars.describe() will give description of which of


the following column?
a. Car name
b. Brand
c. Price (in lakhs)
d. All of the above

Answer: c. Price (in lakhs)


Q4. Which pandas function is used to stack the dataframes vertically?
a. pd.merge()
b. pd.concat()
c. join()
d. None of the above

Answer: b. pd.concat()

Q5. Which of the following are liabraries in Python?


a. Pandas
b. Matplotlib
c. NumPy
d. All of the above

Answer: d. All of the above

Read the comma-separated values file hotel bookings.csv as a


dataframe data hotel and answer questions 6 – 8. Please refer to Hotel
Bookings Data Description.pdf for data and variable description.

Q6. Choose the appropriate command(s) to filter those booking


details whose reservation-status are a No-show?

a.

b.

c.

d.

Answer: b, d
Q7. From the same data, find how many bookings were not canceled
in the year 2017?
a. 9064
b. 6231
c. 9046
d. None of the above

Answer: a. 9064

Q8. From the total bookings that were made in 2017 and not canceled,
which month had the highest number of repeated guests?
a. July
b. February
c. January
d. None of the above

Answer: a. July

Q9. What will be the output of the following code?

a. [bool, int, float, float, str]


b. [str, int, float, float, str]
c. [bool, int, float, int, str]
d. [bool, int, int, float, str]

Answer: a. [bool, int, float, float, str]

Q10. Which command is used to generate the plot shown below?

a. plt.plot(x, linestyle = “-”)


b. plt.plot(x, linestyle = “–”)
c. plt.plot(x, linestyle = “-.”)
d. plt.plot(x, linestyle = “:”)

Answer: a. plt.plot(x, linestyle = “-”)

You might also like