BANA200 Practice Questions
BANA200 Practice Questions
a) 8
b) 9
c) 6
d) 7
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
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?
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(',')
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
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.
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?
False HR 50000
False Finance 55000
True Finance None
False Finance 59000
False IT 65000
True HR 70000
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?
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
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
A er execu on, labels will have exactly one 0 and two 1s.
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:
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.)