# Certified Associate in Python Programming Practice Test 2023

#### Certified Associate in Python Programming Practice Test 2023

Final Prep For The Exam | Test Your Knowledge | Pass The First Time

### Udemy Coupon Discount

Instructions:

1. This practice test consists of multiple-choice questions.
3. There is only one correct answer per question.
5. There is no negative marking for incorrect answers.
6. The total duration of the test is 120 minutes.
7. Try to complete the test within the allotted time.

#### Best of luck!

Section 1: Python Basics

1 .Which of the following is the correct way to print "Hello, World!" in Python?

a) print("Hello, World!")

b) print('Hello, World!')

c) print(Hello, World!)

d) print(Hello, World!)

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

x = 5

y = 2

result = x % y

print(result)

a) 2

b) 3

c) 0

d) 1

3 .Which of the following data types is mutable in Python?

a) int

b) float

c) string

d) list

4 .What will be the value of 'x' after the following code snippet?

x = 10

x += 5

x *= 2

x /= 3

a) 15

b) 20

c) 25

d) 30

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

fruits = ['apple', 'banana', 'orange']

print(fruits[1])

a) 'apple'

b) 'banana'

c) 'orange'

d) Error

Section 2: Control Flow

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

x = 10

if x > 5:

print("x is greater than 5")

else:

print("x is less than or equal to 5")

a) x is greater than 5

b) x is less than or equal to 5

c) 10

d) Error

7 .Which loop is used to iterate over a sequence of elements in Python?

a) for loop

b) while loop

c) do-while loop

d) foreach loop

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

for i in range(1, 5):

if i == 3:

break

print(i)

a) 1 2 3 4

b) 1 2

c) 1 2 4

d) 1 2 3

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

x = 3

while x > 0:

print(x)

x -= 1

a) 1 2 3

b) 3 2 1

c) 1

d) Error

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

x = 0

while x < 5:

x += 1

if x == 3:

continue

print(x)

a) 1 2 3 4 5

b) 1 2 4 5

c) 1 2 4

d) 1 2 3 4

Section 3: Functions and Modules

11 .What is the purpose of the 'return' statement in a Python function?

a) To exit the function

b) To print a value

c) To return a value to the caller

d) To define a function

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

def square(x):

return x * x

result = square(4)

print(result)

a) 8

b) 12

c) 16

d) 20

13 .Which keyword is used to import a module in Python?

a) module

b) import

c) include

d) require

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

import math

print(math.pi)

a) 3.14

b) 3.14159

c) 3

d) Error

15 .What is the purpose of the 'init' method in a Python class?

a) To initialize an object of the class

b) To define class variables

c) To define instance variables

d) To define static methods

Section 4: File Handling

16 .What is the correct way to open a file named "data.txt" for reading in Python?

a) file = open("data.txt", "r")

b) file = open("data.txt", "w")

c) file = open("data.txt", "a")

d) file = open("data.txt", "x")

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

file = open("data.txt", "w")

file.write("Hello, World!")

file.close()

a) Hello, World!

b) Error

c) None

d) True

18 .Which method is used to read the contents of a file in Python?

b) write()

c) append()

d) close()

19 .What is the purpose of the 'with' statement in file handling?

a) To open a file

b) To close a file

c) To ensure proper resource cleanup

d) To read the contents of a file

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

file = open("data.txt", "r")

print(len(lines))

file.close()

a) 0

b) 1

c) 10

d) Error

End of Practice Test

Congratulations on completing the Certified Associate in Python Programming Practice Test! Now, review your answers and calculate your score to assess your knowledge and readiness for the certification exam. Good luck!

INSTRUCTOR