




















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































































Question 1. Which of the following is the correct way to assign the integer value 10 to a variable named counter in Python? A) int counter = 10 B) counter := 10 C) counter = 10 D) let counter = 10 Answer: C Explanation: In Python, assignment uses a single equals sign (=) without any type declaration. Question 2. What is the output of print(type(3.14))? A) <class 'int'> B) <class 'float'> C) <class 'str'> D) <class 'bool'> Answer: B Explanation: 3.14 is a floating‑point literal, so its type is float. Question 3. Which operator performs integer (floor) division in Python? A) / B) // C) % D) ** Answer: B Explanation: The // operator divides and returns the floor of the quotient. Question 4. Which of the following expressions evaluates to True?
5 > 5B) 'apple' == 'Apple' C) 10 != 10 D) 7 <= 7 Answer: D Explanation: 7 <= 7 is true because 7 is equal to 7; the other comparisons are false. Question 5. What does the logical expression not (True and False) evaluate to? A) True B) False C) None D) Error Answer: A Explanation: True and False is False; applying not yields True. Question 6. Which keyword is used to start a conditional block that runs when previous if or elif conditions are false? A) else B) elif C) when D) default Answer: A Explanation: else catches all cases not handled by preceding if/elif. Question 7. How many times will the loop for i in range(3): print(i) execute the print statement?
B) swapcase() C) capitalize() D) upper() Answer: D Explanation: upper() transforms all alphabetic characters to uppercase. Question 11. Given text = " hello world ", which method removes the leading and trailing whitespace? A) strip() B) trim() C) remove() D) cut() Answer: A Explanation: strip() eliminates whitespace at both ends of the string. Question 12. What is the result of "Python".split('y')? A) ['Python'] B) ['P', 'thon'] C) ['Pyt', 'hon'] D) ['Pyt', 'hon'] Answer: C Explanation: Splitting on 'y' removes the delimiter and returns the substrings before and after it. Question 13. Which of the following creates a list containing the numbers 1 through 5? A) {1,2,3,4,5}
(1,2,3,4,5)[1,2,3,4,5]D) list(1,2,3,4,5) Answer: C Explanation: Square brackets define a list; curly braces define a set, parentheses a tuple. Question 14. How can you add the element 10 to the end of the list nums = [1,2,3]? A) nums.add(10) B) nums.append(10) C) nums.insert(10) D) nums.push(10) Answer: B Explanation: append() adds an element to the list’s tail. Question 15. After executing my_list = [0,1,2,3,4]; del my_list[2], what is my_list? A) [0,1,3,4] B) [0,1,2,4] C) [0,2,3,4] D) [1,2,3,4] Answer: A Explanation: del my_list[2] removes the element at index 2 (value 2). Question 16. Which list comprehension creates a list of squares for numbers 0 through 4? A) [x*x for x in range(5)] B) {x*x for x in range(5)}
D) dict("a":1, "b":2) Answer: C Explanation: Dictionaries use colon : to separate keys and values inside {}. Question 20. How can you retrieve the list of keys from a dictionary d = {'x':10, 'y':20}? A) d.values() B) d.keys() C) d.items() D) d.get() Answer: B Explanation: keys() returns a view of the dictionary’s keys. Question 21. Which method removes and returns the value associated with key 'x' from dictionary d? A) d.pop('x') B) d.remove('x') C) del d['x'] D) d.clear('x') Answer: A Explanation: pop() both removes the entry and returns its value. Question 22. What will be printed by the following code?
def foo(a, b=5): return a * b ## with Python Certificate Practice Exam print(foo(3)) A) 8 B) 15 C) 3 D) Error Answer: B Explanation: The default value for b is 5; 3 * 5 = 15. Question 23. In Python, what is the scope of a variable defined inside a function without the global keyword? A) Local to the function B) Global to the module C) Visible in all functions D) Read‑only everywhere Answer: A Explanation: Variables created inside a function are local unless declared global. Question 24. Which built‑in function returns the number of elements in an iterable seq? A) size(seq) B) length(seq) C) count(seq) D) len(seq) Answer: D Explanation: len() is the standard way to obtain length.
Question 28. What does the following code produce?
class Animal: def __init__(self, name): self.name = name dog = Animal('Buddy') print(dog.name) A) Animal B) Buddy C) name D) Error Answer: B Explanation: The constructor stores 'Buddy' in self.name; accessing dog.name yields that value. Question 29. Which of the following statements about class inheritance in Python is true? A) A subclass must explicitly call the parent’s __init__ method. B) Python does not support multiple inheritance. C) The super() function can be used to access parent methods. D) Child classes cannot override parent methods. Answer: C Explanation: super() returns a proxy object to call methods from the base class.
Question 30. In computational thinking, which step involves identifying the essential parts of a problem while ignoring irrelevant details? A) Decomposition B) Pattern Recognition C) Abstraction D) Algorithmic Thinking Answer: C Explanation: Abstraction reduces complexity by focusing on relevant information. Question 31. Which of the following best describes “pattern recognition” in problem solving? A) Breaking a problem into smaller pieces B) Finding similarities or regularities in data C) Writing code that runs faster D) Testing code for bugs Answer: B Explanation: Pattern recognition is about spotting recurring structures. Question 32. When tracing the execution of a Python algorithm, what does a “trace” typically show? A) Memory usage over time B) The values of variables after each step C) The compiled bytecode D) The execution time of each line Answer: B
Explanation: All three produce the same 1‑D array; arange generates a range, linspace creates equally spaced points, and array directly constructs it. Question 36. Given a = np.array([1, 2, 3]) and b = np.array([4, 5, 6]), what is a + b? A) [5, 7, 9] B) [4, 5, 6, 1, 2, 3] C) Error D) [[1,4],[2,5],[3,6]] Answer: A Explanation: NumPy performs element‑wise addition. Question 37. Which method returns the mean of all elements in a NumPy array arr? A) arr.mean() B) np.mean(arr) C) Both A and B D) Neither Answer: C Explanation: Both the array method and the NumPy function compute the mean. Question 38. How would you reshape a NumPy array x of shape (12,) into a 3 × 4 matrix? A) x.reshape(3,4) B) x.resize((3,4)) C) np.shape(x, (3,4)) D) x.transpose(3,4) Answer: A Explanation: reshape returns a view with the new dimensions.
Question 39. Which of the following creates a Pandas Series from the list [10, 20, 30]? A) pd.Series([10,20,30]) B) pd.DataFrame([10,20,30]) C) pd.array([10,20,30]) D) Series([10,20,30]) Answer: A Explanation: pd.Series constructs a one‑dimensional labeled array. Question 40. In Pandas, what does the head() method do? A) Returns the last five rows B) Returns the first five rows C) Returns column names D) Returns data types of columns Answer: B Explanation: head() shows the top rows (default 5). Question 41. Which function reads a CSV file named sales.csv into a DataFrame? A) pd.read_csv('sales.csv') B) pd.load_csv('sales.csv') C) pd.read_excel('sales.csv') D) pd.DataFrame('sales.csv') Answer: A Explanation: read_csv parses CSV files into DataFrames.
Question 45. Which of the following NumPy functions computes the standard deviation of an array arr? A) np.var(arr) B) np.std(arr) C) arr.variance() D) arr.deviation() Answer: B Explanation: np.std returns the standard deviation. Question 46. What does the Pandas expression df['salary'].median() compute? A) The average salary B) The middle value when salaries are sorted C) The most frequent salary D) The sum of all salaries Answer: B Explanation: median() returns the 50th percentile value. Question 47. Which Matplotlib function creates a line plot of x versus y? A) plt.scatter(x, y) B) plt.plot(x, y) C) plt.bar(x, y) D) plt.hist(y) Answer: B Explanation: plot draws lines (or markers) connecting points.
Question 48. In Seaborn, which function is specifically designed for visualizing the distribution of a single quantitative variable? A) sns.boxplot() B) sns.histplot() C) sns.scatterplot() D) sns.heatmap() Answer: B Explanation: histplot creates histograms (or KDE) for one variable. Question 49. Which plot type is most appropriate for comparing categorical frequencies? A) Scatter plot B) Histogram C) Bar chart D) Box plot Answer: C Explanation: Bar charts display counts or aggregates for discrete categories. Question 50. What is the purpose of a box plot? A) Show the relationship between two continuous variables B) Summarize the distribution through quartiles and outliers C) Display frequency of categorical data D) Plot cumulative totals over time Answer: B Explanation: Box plots visualize median, quartiles, and potential outliers. Question 51. Which of the following best defines a “population” in statistics?
B) The mean of a large number of independent, identically distributed variables tends toward a normal distribution. C) Sample variance equals population variance. D) Correlation implies causation. Answer: B Explanation: The theorem explains why sample means approximate normality. Question 55. Which of the following is a correct way to compute the variance of a list data using NumPy? A) np.var(data, ddof=1) B) np.variance(data) C) np.std(data)**2 D) Both A and C Answer: D Explanation: np.var with ddof=1 gives sample variance; squaring the standard deviation also yields variance. Question 56. If x = 5 and y = 0, what will x / y raise in Python? A) ZeroDivisionError B) ValueError C) Infinity D) None Answer: A Explanation: Division by zero triggers a ZeroDivisionError. Question 57. Which of the following statements about mutable default arguments in functions is true?
A) They are recreated each time the function is called. B) They retain changes between calls. C) They cause a syntax error. D) They are automatically deep‑copied. Answer: B Explanation: Default mutable objects (e.g., lists) persist across invocations, which can lead to unexpected behavior. Question 58. Which of the following is NOT a valid Python identifier? A) _temp B) 2ndPlace C) data_frame D) MAX_VALUE Answer: B Explanation: Identifiers cannot start with a digit. Question 59. What is the result of bool([]) in Python? A) True B) False C) [] D) Error Answer: B Explanation: Empty containers are considered falsy. Question 60. Which of the following statements correctly creates a generator expression that yields squares of numbers from 0 to 4?