Docsity

PYTHON INSTITUTE CERTIFIED ASSOCIATE IN PYTHON PROGRAMMING (PCAP) ACTUAL EXAM AND PRACTICE, Exams of Computer Science

Toggle sidebar
bg1
PYTHON INSTITUTE CERTIFIED ASSOCIATE IN PYTHON
PROGRAMMING (PCAP) ACTUAL EXAM AND PRACTICE TESTS
NEWEST 2026-2027 WITH COMPLETE QUESTIONS AND
CORRECT DETAILED ANSWERS| BRAND NEW VERSION!
1. What is the output of the following Python code?
x = 10y = 3print(x // y)
A. 3.33
B. 3
C. 4
D. 1
Correct Answer: B. 3
Rationale: The // operator performs floor division, returning the integer quotient
when both operands are integers.
2. Which keyword is used to define a function in Python?
A. function
B. define
C. def
D. func
Correct Answer: C. def
Rationale: The def keyword introduces a function definition in Python.
3. What is the output of this code?
print(type(3.14))
A. int
B. float
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download PYTHON INSTITUTE CERTIFIED ASSOCIATE IN PYTHON PROGRAMMING (PCAP) ACTUAL EXAM AND PRACTICE and more Exams Computer Science in PDF only on Docsity!

PYTHON INSTITUTE CERTIFIED ASSOCIATE IN PYTHON

PROGRAMMING (PCAP) ACTUAL EXAM AND PRACTICE TESTS

NEWEST 2026-2027 WITH COMPLETE QUESTIONS AND

CORRECT DETAILED ANSWERS| BRAND NEW VERSION!

1. What is the output of the following Python code? x = 10y = 3print(x // y) A. 3. B. 3 C. 4 D. 1 Correct Answer: B. 3 Rationale: The // operator performs floor division, returning the integer quotient when both operands are integers. 2. Which keyword is used to define a function in Python? A. function B. define C. def D. func Correct Answer: C. def Rationale: The def keyword introduces a function definition in Python. 3. What is the output of this code? print(type(3.14)) A. int B. float

C. double D. decimal Correct Answer: B. float Rationale: Python represents floating-point numbers using the float data type.

4. Which of the following data types is immutable? A. List B. Dictionary C. Set D. Tuple Correct Answer: D. Tuple Rationale: Tuples cannot be modified after creation, whereas lists, dictionaries, and sets are mutable. 5. What is the output? x = "Python"print(x[1]) A. P B. y C. t D. Python Correct Answer: B. y Rationale: Python strings use zero-based indexing, so index 1 refers to the second character. 6. Which operator checks whether two values are equal? A. = B. != C. == D. === Correct Answer: C. ==

A. repeat B. foreach C. for D. iterate Correct Answer: C. for Rationale: A for loop iterates over elements of an iterable such as a list, tuple, string, or range.

11. What is the output? x = 5if x > 3: print("Yes")else: print("No") A. No B. Yes C. True D. Error Correct Answer: B. Yes Rationale: Since 5 is greater than 3, the if condition evaluates to True. 12. Which function returns the length of a sequence? A. size() B. count() C. length() D. len() Correct Answer: D. len() Rationale: The built-in len() function returns the number of items in a sequence or collection. 13. What is the output? print("Python" + "3") A. Python 3 B. Python C. Python+ D. Error

Correct Answer: B. Python Rationale: The + operator concatenates two strings without automatically inserting a space.

14. Which statement terminates a loop immediately? A. stop B. exit C. break D. continue Correct Answer: C. break Rationale: The break statement immediately terminates the nearest enclosing loop. 15. What does the continue statement do? A. Terminates the program B. Skips the current iteration C. Exits the function D. Restarts the program Correct Answer: B. Skips the current iteration Rationale: The continue statement skips the remaining statements in the current loop iteration and proceeds to the next iteration. 16. What is the output? x = [10, 20, 30, 40]print(x[-1]) A. 10 B. 20 C. 30 D. 40 Correct Answer: D. 40 Rationale: Negative indexing starts from the end of a list, and - 1 identifies its last element.

C. Error D. None Correct Answer: C. Error Rationale: Dividing by zero raises ZeroDivisionError, which is caught by the except block.

21. Which keyword returns a value from a function? A. yield B. return C. break D. output Correct Answer: B. return Rationale: The return statement ends function execution and sends a value back to the caller. 22. What is the output? def add(a, b): return a + bprint(add(4, 6)) A. 46 B. 10 C. 4 D. 6 Correct Answer: B. 10 Rationale: The function adds the two numerical arguments and returns their sum. 23. What is the default return value of a Python function without an explicit return statement? A. 0 B. False C. None D. Empty string Correct Answer: C. None

Rationale: Python functions implicitly return None when execution finishes without an explicit return value.

24. Which statement imports the math module? A. include math B. using math C. import math D. load math Correct Answer: C. import math Rationale: The import statement makes the specified module available in the current namespace. 25. What is the output? import mathprint(math.sqrt(81)) A. 8 B. 9. C. 81 D. 9 Correct Answer: B. 9. Rationale: math.sqrt() calculates the square root and returns a floating-point result. 26. Which method converts a string to lowercase? A. lower() B. lowercase() C. small() D. casefolding() Correct Answer: A. lower() Rationale: The lower() string method returns a new string with all cased characters converted to lowercase. 27. What is the output?

C. object Student: D. new class Student: Correct Answer: A. class Student: Rationale: The class keyword defines a new class in Python.

31. What is the purpose of the init () method? A. To delete an object B. To initialize a newly created object C. To import a module D. To terminate a class Correct Answer: B. To initialize a newly created object Rationale: The init() method initializes an object's attributes after the instance has been created. 32. What does self represent in an instance method? A. The parent class B. The current instance C. The module D. A global variable Correct Answer: B. The current instance Rationale: The self parameter conventionally refers to the current object instance and provides access to its attributes and methods. 33. Which concept allows a class to inherit attributes and methods from another class? A. Encapsulation B. Polymorphism C. Inheritance D. Abstraction Correct Answer: C. Inheritance Rationale: Inheritance allows a derived class to reuse and extend functionality defined in a base class.

34. What is the output? class A: value = 10obj = A()print(obj.value) A. None B. 0 C. 10 D. Error Correct Answer: C. 10 Rationale: The instance can access the class attribute value through the object. 35. Which built-in function checks the type of an object? A. typeof() B. type() C. checktype() D. objecttype() Correct Answer: B. type() Rationale: The type() function returns the type of an object. 36. What is the output? x = [1, 2, 3]y = xy.append(4)print(x) A. [1, 2, 3] B. [1, 2, 3, 4] C. [4] D. Error Correct Answer: B. [1, 2, 3, 4] Rationale: Both variables refer to the same list object, so modifying the list through y also affects what x references. 37. Which function converts a value into an integer when possible? A. str() B. float()

Rationale: A set stores unique hashable elements and does not guarantee insertion-order iteration.

41. What is the output? a = {1, 2, 3}b = {3, 4, 5}print(a & b) A. 5 B. 2 C. 3 D. 5 Correct Answer: C. 3 Rationale: The & operator performs set intersection, returning elements common to both sets. 42. Which dictionary method returns all key-value pairs? A. keys() B. values() C. items() D. pairs() Correct Answer: C. items() Rationale: The items() method returns a view containing the dictionary's key- value pairs. 43. What happens when a dictionary key is accessed using square brackets and the key does not exist? A. It returns None B. It returns False C. It raises KeyError D. It creates the key automatically Correct Answer: C. It raises KeyError Rationale: Accessing a missing dictionary key with square brackets raises KeyError. The get() method can instead return a default value. 44. Which statement opens a file for reading?

A. open("data.txt", "w") B. open("data.txt", "r") C. open("data.txt", "a") D. open("data.txt", "x") Correct Answer: B. open("data.txt", "r") Rationale: The r mode opens an existing file for reading without modifying its contents.

45. What is the main advantage of using a with statement when working with files? A. It automatically encrypts the file B. It automatically closes the file when the block exits C. It converts the file into a list D. It prevents all file errors Correct Answer: B. It automatically closes the file when the block exits Rationale: A context manager handles resource cleanup, ensuring that the file is closed when the with block finishes. 46. What is the output? x = [1, 2, 3, 4, 5]print(x[::2]) A. [1, 2, 3] B. [2, 4] C. [1, 3, 5] D. [5, 3, 1] Correct Answer: C. [1, 3, 5] Rationale: The slice step of 2 selects every second element, beginning with index zero. 47. Which statement is correct about local variables? A. They are accessible everywhere in the program B. They are defined within a function or local scope

Correct Answer: B. 20 10 Rationale: Python supports multiple assignment, allowing two variables to exchange their values simultaneously without requiring a temporary variable.

51. What is the output of the following code? x = [1, 2, 3]x.insert(1, 10)print(x) A. [1, 2, 3, 10] B. [10, 1, 2, 3] C. [1, 10, 2, 3] D. [1, 2, 10, 3] Correct Answer: C. [1, 10, 2, 3] Rationale: The insert() method places an element at the specified index. Index 1 is the second position. 52. What is the output? x = [1, 2, 3, 2]print(x.count(2)) A. 1 B. 2 C. 3 D. 4 Correct Answer: B. 2 Rationale: The count() method returns the number of occurrences of the specified element. 53. Which method sorts a list in place? A. sorted() B. order() C. sort() D. arrange() Correct Answer: C. sort()

Rationale: The list sort() method modifies the original list. The sorted() function instead returns a new sorted list.

54. What is the output? numbers = [4, 1, 3, 2]numbers.sort()print(numbers) A. [4, 3, 2, 1] B. [1, 2, 3, 4] C. [2, 1, 3, 4] D. None Correct Answer: B. [1, 2, 3, 4] Rationale: The sort() method arranges list elements in ascending order by default. 55. Which expression creates a list containing the squares of numbers from 0 through 4? A. [x * 2 for x in range(5)] B. [x ** 2 for x in range(5)] C. [x + 2 for x in range(5)] D. [x / 2 for x in range(5)] Correct Answer: B. [x ** 2 for x in range(5)] Rationale: The list comprehension calculates the square of every integer generated by range(5). 56. What is the output? result = [x for x in range(6) if x % 2 == 0]print(result) A. [1, 3, 5] B. [0, 2, 4] C. [2, 4, 6] D. [0, 1, 2, 3, 4, 5] Correct Answer: B. [0, 2, 4] Rationale: The condition selects only numbers whose remainder after division by 2 is zero.

Rationale: enumerate() starts counting at zero by default and returns each index together with its corresponding value.

59. Which statement correctly describes a Python lambda function? A. It must contain multiple statements B. It creates an anonymous function C. It defines a class D. It imports another function Correct Answer: B. It creates an anonymous function Rationale: A lambda expression creates a small anonymous function consisting of a single expression. 60. What is the output? square = lambda x: x ** 2print(square(5)) A. 10 B. 15 C. 25 D. 5 Correct Answer: C. 25 Rationale: The lambda function squares its argument, and 5 raised to the power of 2 equals 25. 61. Which function applies a given function to every element of an iterable? A. filter() B. map() C. reduce() D. zip() Correct Answer: B. map() Rationale: map() applies the specified function to each element and returns an iterator containing the results. 62. What is the output?

numbers = [1, 2, 3]result = list(map(lambda x: x * 2, numbers))print(result) A. [1, 2, 3] B. [2, 4, 6] C. [3, 4, 5] D. [1, 4, 9] Correct Answer: B. [2, 4, 6] Rationale: The lambda function multiplies every list element by 2, and list() converts the map iterator into a list.

63. What is the purpose of the filter() function? A. To sort elements B. To remove duplicate elements automatically C. To select elements satisfying a condition D. To convert integers into strings Correct Answer: C. To select elements satisfying a condition Rationale: filter() produces an iterator containing elements for which the supplied function returns a truthy value. 64. What is the output? numbers = [1, 2, 3, 4, 5, 6]result = list(filter(lambda x: x > 3, numbers))print(result) A. [1, 2, 3] B. [3, 4, 5, 6] C. [4, 5, 6] D. [1, 2, 3, 4, 5, 6] Correct Answer: C. [4, 5, 6] Rationale: The filtering condition retains only elements greater than 3. 65. What does the zip() function do? A. Compresses files B. Combines corresponding elements from multiple iterables C. Sorts multiple lists D. Removes repeated values