D522 Python for IT Automation – Objective Assessment (OA) Section 1: Python Fundamentals, Exams of Information Technology

D522 Python for IT Automation – Objective Assessment (OA) Section 1: Python Fundamentals and Syntax

Typology: Exams

2025/2026

Available from 06/30/2026

TANA232
TANA232 🇺🇸

1.5K documents

1 / 66

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
D522 Python for IT Automation Objective
Assessment (OA)
Section 1: Python Fundamentals and Syntax
Question 1
What is the output of the following code?
python
x = 5
y = 2
print(x // y)
A) 2.5
B) 2
C) 3
D) 2.0
Correct Answer: B) 2
Rationale: The // operator performs floor division in Python, which returns the integer quotient
rounded down to the nearest whole number. 5 // 2 equals 2, not 2.5. The / operator would
return 2.5, but // specifically returns an integer result.
Question 2
Which of the following is NOT a valid Python data type?
A) int
B) float
C) double
D) str
Correct Answer: C) double
Rationale: Python does not have a 'double' data type. It uses 'float' for floating-point numbers,
which in Python is equivalent to a double in other languages (implemented as a C double). The
other options (int, float, str) are all valid Python data types.
Question 3
What will be the output of this code?
python print(type(3.14))
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42

Partial preview of the text

Download D522 Python for IT Automation – Objective Assessment (OA) Section 1: Python Fundamentals and more Exams Information Technology in PDF only on Docsity!

D522 Python for IT Automation – Objective

Assessment (OA)

Section 1: Python Fundamentals and Syntax

Question 1 What is the output of the following code?

python

x = 5

y = 2

print(x // y)

A) 2. B) 2 C) 3 D) 2.

Correct Answer: B) 2 Rationale: The // operator performs floor division in Python, which returns the integer quotient rounded down to the nearest whole number. 5 // 2 equals 2, not 2.5. The / operator would return 2.5, but // specifically returns an integer result.

Question 2 Which of the following is NOT a valid Python data type? A) int B) float C) double D) str

Correct Answer: C) double Rationale: Python does not have a 'double' data type. It uses 'float' for floating-point numbers, which in Python is equivalent to a double in other languages (implemented as a C double). The other options (int, float, str) are all valid Python data types.

Question 3 What will be the output of this code?

python print(type(3.14))

A) B) C) D)

Correct Answer: B) Rationale: In Python, numbers with decimal points are classified as floats. 3.14 is a floatingpoint number, so type() returns . Python does not have a double type, and 3.14 is not an integer.

Question 4 Which of the following is used to create a comment in Python? A) // B) /* */ C) # D) --

Correct Answer: C) # Rationale: In Python, the # symbol is used to create single-line comments. Everything after # on that line is ignored by the interpreter. // is used in languages like C++ and Java for comments, /* */ is used for multi-line comments in some languages, and -- is used in SQL.

Question 5 What is the output of len("Python Automation")? A) 16 B) 17 C) 18 D) 19

Correct Answer: B) 17 Rationale: The len() function counts the number of characters in a string, including spaces. "Python Automation" has 6 letters in "Python" + 1 space + 10 letters in "Automation" = 17 characters total.

Question 6 Which operator is used for exponentiation in Python? A) ^ B) ** C) * D) ++ **Correct Answer: B) **

Correct Answer: B) 1 Rationale: The % operator in Python is the modulo operator, which returns the remainder of a

division operation. 10 divided by 3 equals 3 with a remainder of 1, so 10 % 3 = 1.

Question 10 Which keyword is used to define a function in Python? A) function B) def C) define D) func

Correct Answer: B) def

Rationale: The 'def' keyword is used to define a function in Python. It is short for "define" and is followed by the function name, parentheses for parameters, and a colon. The other options are not valid Python keywords for function definition.

Question 11 What will be the output of print("Hello " * 3)? A) Hello Hello Hello B) HelloHelloHello C) Hello 3 D) Error

Correct Answer: A) Hello Hello Hello Rationale: The * operator when used with a string and an integer performs string repetition. "Hello " * 3 produces "Hello Hello Hello " (note the trailing space). The string "Hello " is repeated three times, preserving the space after Hello.

Question 12 Which of the following is NOT a valid variable name in Python? A) my_var B) my_var C) 1_my_var D) myVar

Correct Answer: C) 1_my_var Rationale: Python variable names cannot start with a number. They can only start with a letter (a-z, A-Z) or an underscore (_). The rest of the name can contain letters, numbers, and underscores. 1_my_var starts with a number, making it invalid.

Question 13

What is the output of int(3.9)? A) 3 B) 4 C) 3. D) Error

Correct Answer: A) 3 Rationale: The int() function truncates the decimal portion of a float, effectively rounding towards zero. int(3.9) returns 3, not 4. It does not round to the nearest integer; it simply removes the decimal part.

Question 14 Which method is used to remove whitespace from both ends of a string? A) strip() B) trim() C) remove() D) clean()

Correct Answer: A) strip() Rationale: The strip() method in Python removes leading and trailing whitespace from a string. It does not modify the original string (strings are immutable) but returns a new string. trim() is used in other languages like JavaScript, and remove() and clean() are not standard string methods in Python.

Question 15 What does the is operator compare in Python? A) Values B) Memory addresses C) Types D) Lengths

Correct Answer: B) Memory addresses Rationale: The is operator checks if two variables refer to the exact same object in memory (identity comparison). It does not compare values like the == operator does. is returns True if both variables point to the same object.

Question 16 What will be the output of this code?

python

B) 512

C) 256

D) 12

Correct Answer: B) 512 Rationale: In Python, the exponentiation operator ** has right-to-left associativity. This means 2 ** 3 ** 2 is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512, not (2 ** 3) ** 2 which would be 64.

Question 20 Which of the following is a mutable data type in Python? A) tuple B) string C) list D) int

Correct Answer: C) list Rationale: Lists are mutable in Python, meaning their contents can be changed after creation. Tuples and strings are immutable (cannot be changed after creation). Integers are also immutable objects in Python.

Section 2: Control Flow and Loops

Question 21 What is the output of this code?

python

x = 10 if

x > 5:

print("Greater") else:

print("Less")

A) Greater B) Less C) Error D) None

Correct Answer: A) Greater Rationale: The condition x > 5 evaluates to True (10 > 5), so the code block under the if statement executes, printing "Greater". The else block is skipped. Question 22 Which loop in Python is used when you know the number of iterations in advance?

A) while B) for C) do-while D) until

Correct Answer: B) for Rationale: The for loop in Python is typically used when you know the number of iterations in advance or when iterating over a sequence. A while loop is used when the number of iterations is unknown and depends on a condition. Python doesn't have do-while or until loops.

Question 23 What will be the output of this code?

python

for i in range(3):

print(i, end=" ")

A) 0 1 2 B) 1 2 3 C) 0 1 2 3 D) 1 2 3 4

Correct Answer: A) 0 1 2 Rationale: The range(3) function generates numbers from 0 to 2 (3 numbers). The loop iterates through these values and prints each one. The end=" " parameter ensures they are printed on the same line with a space between them.

Question 24 What is the output of this code?

python

x = 0 while

x < 3:

print(x) x

+= 1

A) 0 1 2 B) 1 2 3 C) 0 1 2 3

python

x = 10 if

x < 5:

print("Less") elif

x < 15:

print("Medium")

else:

print("High")

A) Less B) Medium C) High D) Error

Correct Answer: B) Medium Rationale: The first condition x < 5 is False (10 < 5 is False). The elif condition x < 15 is True (10 < 15 is True), so the code block under elif executes, printing "Medium". The else block is skipped.

Question 28 Which of the following is a valid use of the continue statement? A) To skip the rest of the loop iteration B) To terminate the loop C) To restart the loop D) To check a condition

Correct Answer: A) To skip the rest of the loop iteration Rationale: The continue statement in Python is used to skip the remaining code in the current iteration of a loop and proceed to the next iteration. It does not terminate the loop; only break does that.

Question 29 What will be the output of this code?

python

for i in range(3):

for j in range(2):

print(i + j, end=" ")

A) 0 1 1 2 2 3

B) 0 1 1 2 3 4

C) 0 1 2 3 4 5

D) 0 1 2 1 2 3

Correct Answer: A) 0 1 1 2 2 3 Rationale: The outer loop runs i=0,1,2. For each i, the inner loop runs j=0,1. The values printed are i+j. For i=0: 0,1. For i=1: 1,2. For i=2: 2,3. So the output is "0 1 1 2 2 3".

Question 30 What is the output of this code?

python

x = 5 if

x > 3:

print("A")

if x > 4:

print("B")

else:

print("C")

A) A B) A B C) A B C D) C

Correct Answer: B) A B Rationale: The outer if condition x > 3 is True (5 > 3), so "A" is printed. Inside that block, the inner if condition x > 4 is also True (5 > 4), so "B" is printed. The else block for the outer if is skipped because the condition was True.

Question 31

Rationale: In Python, the else clause in a loop (for or while) executes when the loop completes normally without encountering a break statement. If the loop is terminated by break, the else block is skipped. Question 34 What will be the output of this code?

python

for i in range(3):

if i == 1:

break else:

print("Done")

A) Done B) Nothing C) Error D) 1 Done

Correct Answer: B) Nothing Rationale: The loop runs from i=0 to i=2. When i=1, the break statement is executed, terminating the loop. Since the loop was terminated by break, the else block (which executes only when the loop completes normally) is skipped, so nothing is printed.

Question 35 Which statement creates an infinite loop in Python? A) while True: B) for i in range(0): C) while False: D) for i in range(10):

Correct Answer: A) while True: Rationale: while True: creates an infinite loop because the condition is always True. Unless there's a break statement inside, the loop will run forever. The other options either run a finite number of times or not at all.

Question 36 What is the output of this code?

python

x = 5

if x: print("True")

else:

print("False")

A) True B) False C) Error D) 5

Correct Answer: A) True Rationale: In Python, when a number is used in a boolean context, it evaluates to True if it's non-zero, and False if it's zero. Since x = 5 (non-zero), it evaluates to True, so "True" is printed.

Question 37 Which of the following is used to combine multiple conditions in an if statement? A) AND, OR, NOT B) &&, ||,! C) and, or, not D) &, |, ~

Correct Answer: C) and, or, not Rationale: Python uses the keywords 'and', 'or', and 'not' for logical operations. The other options (&&, ||, !) are used in languages like C++ and Java. Python does not use these symbols for logical operations.

Question 38 What will be the output of this code?

python

x = 4 if x > 2 and

x < 5:

print("Yes") else: print("No")

A) Yes B) No C) Error D) Maybe

Correct Answer: B) list Rationale: Lists in Python are ordered, mutable (can be modified after creation), and allow duplicate elements. Tuples are ordered and allow duplicates but are immutable. Sets are unordered, mutable, but do not allow duplicates. Dictionaries are unordered (in older Python versions) and use key-value pairs.

Question 42 What is the output of this code?

python

my_list = [1, 2, 3, 4, 5] print(my_list[2])

A) 2 B) 3 C) 4 D) 5

Correct Answer: B) 3 Rationale: In Python, list indexing starts at 0. So my_list[0] = 1, my_list[1] = 2, and my_list[2] = 3. Therefore, the output is 3.

Question 43 Which method is used to add an element to the end of a list? A) push() B) add() C) append() D) insert()

Correct Answer: C) append() Rationale: The append() method adds a single element to the end of a list. The insert() method adds an element at a specific index. push() is used in other languages like JavaScript. add() is used for sets in Python.

Question 44 What will be the output of this code?

python my_tuple = (1, 2, 3) my_tuple[0]

= 4 print(my_tuple)

A) (4, 2, 3) B) (1, 2, 3)

C) Error D) (4, 2, 3, 4)

Correct Answer: C) Error Rationale: Tuples in Python are immutable, meaning their elements cannot be changed after creation. Attempting to assign a new value to an element of a tuple raises a TypeError: 'tuple' object does not support item assignment.

Question 45 Which data structure would you use to store unique elements with no duplicate values?

A) list B) tuple C) set D) dict

Correct Answer: C) set Rationale: Sets are designed to store unique elements. They automatically remove duplicates. Lists and tuples allow duplicates. Dictionaries store key-value pairs, where keys must be unique but values can be duplicates.

Question 46 What is the output of this code?

python

my_set = {1, 2, 3, 2, 4, 3} print(len(my_set))

A) 6 B) 4 C) 3 D) 5 Correct Answer: B) 4 Rationale: Sets do not allow duplicate elements. When my_set is created, duplicates 2 and 3 are automatically removed. The unique elements are {1, 2, 3, 4}, so the length is 4.

Question 47 Which of the following creates an empty dictionary? A) {} B) [] C) () D) set()

D) Error

Correct Answer: C) 5 Rationale: Negative indexing in Python starts from the end of the list. -1 refers to the last element, -2 refers to the second-to-last, and so on. Therefore, my_list[-1] returns 5, the last element of the list.

Question 51 Which of the following is a correct way to create a dictionary with initial values? A) {"name": "Bob", "age": 25} B) dict(name="Bob", age=25) C) Both A and B D) Only A

Correct Answer: C) Both A and B Rationale: Both methods are valid ways to create dictionaries in Python. The first uses curly braces and key-value pairs. The second uses the dict() constructor with keyword arguments. Both produce the same dictionary.

Question 52 What will be the output of this code?

python

my_list = [1, 2, 3, 4] my_list.append([5, 6]) print(len(my_list))

A) 6 B) 5 C) 4 D) 3

Correct Answer: B) 5 Rationale: append() adds a single element to the end of the list. Here, the element being added is a list [5, 6] as a single object. The original list has 4 elements, and after appending one list, it has 5 elements. The total number of elements is 5, not 6.

Question 53 What is the purpose of the extend() method in a list? A) Adds a single element to the end B) Adds multiple elements by iterating through an iterable C) Inserts an element at a specific position D) Removes all elements from the list

Correct Answer: B) Adds multiple elements by iterating through an iterable Rationale: The extend() method adds all elements from an iterable (like another list, tuple, or set) to the end of the list, effectively merging them. Unlike append(), which adds the entire iterable as a single element, extend() adds each element individually.

Question 54 What will be the output of this code?

python

my_dict = {"a": 1, "b": 2, "c": 3}

for key in my_dict: print(key,

end=" ")

A) a b c B) 1 2 3 C) a b c 1 2 3 D) Error

Correct Answer: A) a b c Rationale: When iterating over a dictionary, the default iteration is over its keys. The loop prints each key (a, b, c) separated by spaces. To iterate over values or key-value pairs, you would need to use .values() or .items().

Question 55 Which data structure maintains insertion order in Python? A) set B) dict (from Python 3.7+) C) tuple D) All of the above

Correct Answer: D) All of the above Rationale: Starting from Python 3.7, dictionaries maintain insertion order. Sets are unordered in Python (they do not maintain insertion order). Tuples maintain the order of elements. Lists also maintain insertion order. So the question as written has an issue - sets do NOT maintain insertion order.

Question 56 What will be the output of this code?