0% found this document useful (0 votes)
29 views9 pages

BANA200 Practice Questions

This document contains a multiple choice quiz on Python concepts like data types, operators, loops, strings, lists, and pandas. It also includes true/false questions and coding exercises. The questions cover core Python topics as well as common data analysis and machine learning techniques like data preprocessing, K-Means clustering, and handling outliers.

Uploaded by

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

BANA200 Practice Questions

This document contains a multiple choice quiz on Python concepts like data types, operators, loops, strings, lists, and pandas. It also includes true/false questions and coding exercises. The questions cover core Python topics as well as common data analysis and machine learning techniques like data preprocessing, K-Means clustering, and handling outliers.

Uploaded by

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

A.

Mul ple‐Choice Ques ons

1. Which of the following is NOT a core Python func on?


a) type()
b) len()
c) print()
d) describe()

2. What is the output of the following expression:


5 ** 2 // 3?

a) 8
b) 9
c) 6
d) 7

3. What is the result of the expression 5 < 3 or 2 > 1?


a) True
b) False
c) Neither True nor False
d) Error

4. Which loop will run indefinitely?


a) for i in range(5):
print(i)
b) while False:
print("Hello")
c) for i in "PYTHON":
print(i)
d) while 5<=5:
print("Hello")

1
5. What will be the output of the following code?

for i in range(3):
if i == 1:
break
print(i)

a) b) c) d)

0 1 0 0
1 1
2

6. What is the output of the following code?

s = "Hello, World"
output = s.split(",")
print(output)

a) ['Hello', 'World']
b) 'Hello, World'
c) ['H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd']
d) None of the above

7. Given two lists, a = [1, 2, 3] and b = [4, 5, 6]. What is the result of a + b?
a) [5, 7, 9]
b) [1, 2, 3, 4, 5, 6]
c) [4, 5, 6, 1, 2, 3]
d) Error

2
8. What is the output of the following?

a = ["Hello", "World", "Python"]


b=a
b[0] = "Java"
print(a[0])
a) "Hello"
b) "World"
c) "Java"
d) "Python"

9. Given the string s = "PYTHON", what is the result of s[1:4]?


a) "YTH"
b) "YTHO"
c) "PYT"
d) "PYTO"

10. Which func on will convert a list of strings into a single string with each element separated by a
comma?
a) ','.append(list)
b) ','.concat(list)
c) ','.join(list)
d) list.join(',')

11. In the code below, which line will raise an error?

1: a = [1, 2, 3]
2: b = a
3: b[0] = 10
4: c = a + 5

a) Line 1
b) Line 2 list has to be appended and not added
c) Line 3
d) Line 4

3
12. In the code below, which line will raise an error?

1: a = (1, 2, 3)
2: a[1] = 10 Tuples are immutable — ( )
3: print(a[1]) List are mutable — [ ]
a) Line 1
b) Line 2
c) Line 3
d) None of the above

13. Intended to check if a list contains duplicate (repe ve) values. Which condi on must be in the
blank to complete the code?
def has_duplicates(lst):
for i in lst:
if ……………………:
return True
return False

a) lst.count(i) > 0
element i in lst happened more than once
b) lst.count(i) != 0
i has taken the values from lst more than once because it went over all the el
c) lst.count(i) == 1
d) lst.count(i) != 1

14. What does the df.dropna() func on do? when not specified by
a) Drops the DataFrame df. default it removes rows

b) Removes columns with any NaN values.


c) Removes rows with any NaN values.
d) Fills NaN values with zeros.

15. Consider a DataFrame df with a column 'grades'. Which command will replace NaN values in the
'grades' column with the mean of the column?
a) df.fillna(df['grades'].mean())
b) df['grades'].fillna(df['grades'].mean())
c) df['grades'] = df['grades'].mean()
d) df['grades'].replace(np.nan, df['grades'].mean())

4
16. If df is a DataFrame and you run the command df.loc[3:5], what does this return?
a) Columns with numbers 3 and 4 of the DataFrame.
pandas : loc works on
b) Rows with indices 3 and 4 of the DataFrame. rows only
c) Columns with numbers 3, 4, and 5 of the DataFrame.
d) Rows with indices 3, 4, and 5 of the DataFrame.

17. Which method primarily depends on the standard devia on and mean to detect outliers?
a) Z‐score
b) IQR IQR works on the median
c) Transforming data using log
d) None

18. Scaling con nuous data is a common preprocessing step in machine learning and data analysis.
Which of the following statements about scaling is true?
a) Scaling changes the distribu on of the data. we scale to give everything same importance

b) Scaling makes all features have the same importance in distance‐based algorithms.
c) A er using MinMaxScaler, the variance of the data remains the same.
d) None of the above.

19. Why might scaling be crucial before applying K‐Means clustering?


a) To ensure faster computa on
b) To ensure uniformity in data representa on
c) To prevent distance measures from being biased by variables with larger scales
d) To increase the number of clusters

20. Given that K‐Means relies heavily on distance metrics, why might it be vulnerable to features with
different scales?
a) It will lead to more itera ons in the K‐Means algorithm
b) Features with smaller scales will always be clustered together
c) Features with larger scales might dominate the distance computa on
d) It will reduce the number of clusters

21. When using K‐Means, if you have prior knowledge that one feature is more important than
another in determining clusters, how might you incorporate this knowledge?
a) Increase the number of clusters
b) Use a weighted distance measure
c) Decrease the number of itera ons
d) Use Manha an distance measure

5
22. Given the dataset below, which columns can we consider for data transforma on?

Senior Department Salary

False HR 50000
False Finance 55000
True Finance None
False Finance 59000
False IT 65000
True HR 70000

a) Senior, Department, Salary


categorical variable = get the dummies
b) Department, Salary
c) Salary
d) None

23. If, during the K‐Means process, data points stop moving between clusters but the centroids are
s ll being recalculated, what can be inferred?

a) The algorithm has converged


b) There's a bug in the implementa on
c) The number of clusters is too high
d) The ini aliza on was incorrect

6
B. True/False Ques ons

24. In Python, the expression 5 <= x <= 10 is a valid way to check if a number x is between 5 and 10,
inclusive. True

25. The Interquar le Range (IQR) method for detec ng outliers is based on the spread of the middle
50% of the data. True

26. In K‐Means clustering, if you increase the value of K, the intra‐cluster distances will always increase.
False Intra cluster is inside the cluster

27. Lists in Python are mutable, meaning you can modify their content without crea ng a new list
object. True

28. If a dataset has more outliers on the higher end, applying a logarithmic transforma on might help
in reducing the impact of those outliers. True

29. Par onal clustering methods, like K‐Means, work by crea ng a hierarchical tree of clusters.
False

30. The "elbow method" in K‐Means clustering is used to determine the op mal number of itera ons
for convergence. False

31. The opera on ["a", "b"] + ["c"] in Python will result in an error. True

32. Pandas DataFrames are immutable; any opera on that modifies them will return a new object.
False

33. Removing duplicates from a dataset can be considered a method to handle outliers.
False

34. Consider this Python code: True pop removes the item

data = ["apple", "banana", "cherry"]


result = data.pop(1)

A er execu on, result will hold the value "banana" and data will be ["apple", "cherry"].

7
35. Consider this K‐Means clustering code: False

from sklearn.cluster import KMeans


X = [[1, 2], [5, 6], [8, 9]]
kmeans = KMeans(n_clusters=2).fit(X)
labels = kmeans.labels_

A er execu on, labels will have exactly one 0 and two 1s.

C. Write Code Ques ons

1. Given a number n, if n is even, divide it by 2. If n is odd, mul ply it by 3 and add 1. Repeat this
process with the resul ng value. Write a program that returns the sequence of numbers
generated by this process, stopping when the sequence reaches the number 1. For instance, for
n=6, the sequence is [6, 3, 10, 5, 16, 8, 4, 2, 1].

2. Given a list of numbers and a target number, write a func on that finds two dis nct numbers in
the list that add up to the target number, and returns their index. If no two dis nct numbers add
up to the target, the func on returns the value ‐1 as their indexes. In case there are more than 2
pairs of elements in the list that can add up to the target number, your first return value must be
the smallest index.
As an example, a er running your program for the list 𝑖𝑛𝑝𝑢𝑡_𝑙𝑖𝑠𝑡 2, 7, 11, 15 and target
number 9, the return values should be 0 and 1, because 𝑖𝑛𝑝𝑢𝑡_𝑙𝑖𝑠𝑡 0 𝑖𝑛𝑝𝑢𝑡_𝑙𝑖𝑠𝑡 1 9.

3. Write a func on that takes an integer less than 50 as input and returns its Roman numeral
representa on. For example, for the number 4, the output should be "IV", and for the number 9,
the output should be "IX".

4. When two strings are “one edit away” from each other, it means that the two strings are iden cal,
except for one character. The different character can be something else, or it might be missing:

‐ Different character: hello → hillo


‐ Missing character: hello → helo

8
Write a func on that takes two strings as inputs and checks to see if they are one edit away. (Hint:
You may consider checking the length of the two strings.)

You might also like