

































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!


































IT & Cybersecurity Exam coverage: I. Section 1 (Q1-25): Python Basics — syntax, print(), input(), comments, variables, data types (int, float, str, bool), operators (+, - , *, /, //, %, **). II. Section 2 (Q26-50): Control Flow & Functions — if/elif/else, for/while loops, range(), def functions, comparison operators, logical operators (and, or, not). III. Section 3 (Q51-75): Data Structures — lists (append, pop, indexing), tuples, dictionaries (keys, values), sets, list/tuple/dict operations. IV. Section 4 (Q76-100): Advanced Topics — string methods (split, join, upper, lower, find, strip), file I/O (open, read, write), exceptions (try-except), type conversion, Boolean evaluation.
1. In Python, which function is used to display output to the console? A) console.log() B) printf() C) System.out.println() D) print() ✓ (CORRECT)
E) echo() RATIONALE: The built-in print() function is the standard way to display output in Python. The other options are syntax from JavaScript (console.log), C (printf), Java (System.out.println), and PHP (echo), respectively.
2. What is the correct syntax for a single-line comment in Python? A) // This is a comment B) /* This is a comment / C) # This is a comment ✓ (CORRECT) D) E) ' This is a comment RATIONALE: In Python, the hash symbol (#) denotes a single-line comment. Everything after # on that line is ignored by the interpreter. // is used in C++, Java, and JavaScript, while / */ is used for multi-line comments in those languages. 3. Which of the following is NOT a valid variable name in Python? A) my_variable B) _private C) 2nd_place D) myVariable ✓ (CORRECT) E) variable RATIONALE: Variable names in Python cannot start with a
6. What is the output of print(10 / 3) in Python 3? A) 3 B) 3. C) 3.3333333333333335 ✓ (CORRECT) D) 3. E) 4 RATIONALE: In Python 3, the / operator always returns a float, performing true division. The result of 10 divided by 3 is approximately 3.3333333333333335 due to floating-point representation. 7. What is the output of print(10 // 3)? A) 3 ✓ (CORRECT) B) 3. C) 3. D) 4 E) 1 RATIONALE: The // operator performs floor division, returning the integer quotient rounded down. 10 divided by 3 equals 3 with a remainder of 1, so floor division returns 3. 8. What is the output of print(10 % 3)? A) 1 ✓ (CORRECT) B) 2 C) 3 D) 0
RATIONALE: The % operator is the modulo operator, which returns the remainder of a division. 10 divided by 3 equals 3 with a remainder of 1, so 10 % 3 equals 1.
9. What is the output of print(not True)? A) True B) False ✓ (CORRECT) C) 1 D) 0 E) None RATIONALE: The not operator is a logical negation operator. It negates the Boolean value: not True equals False, and not False equals True. 10. What is the output of print(1 == True)? A) True ✓ (CORRECT) B) False C) 1 D) 0 E) Error RATIONALE: In Python, True is equivalent to 1 and False is equivalent to 0. The equality comparison 1 == True returns True because they are considered equal in value.
RATIONALE: Python does not have native multi-line comment syntax, but triple quotes (""" or ''') are commonly used as multi-line strings that effectively serve as comments when not assigned to a variable.
14. What is the output of print("Hello" * 3)? A) HelloHelloHello ✓ (CORRECT) B) Hello C) Hello Hello Hello D) Error E) Hello* RATIONALE: The * operator, when used with a string and an integer, repeats the string. "Hello" * 3 results in "HelloHelloHello". 15. Which function is used to get user input in Python? A) input() ✓ (CORRECT) B) get_input() C) scan() D) read() E) prompt() RATIONALE: The built-in input() function reads a line from standard input and returns it as a string. The other options are not valid Python input functions.
16. What is the output of print(3 ** 2)? A) 6 B) 9 ✓ (CORRECT) C) 3. D) 8 E) 5 RATIONALE: The ** operator is the exponentiation operator in Python. 3 ** 2 means 3 raised to the power of 2, which equals
17. Which statement correctly declares a variable named "age" with a value of 25? A) int age = 25 B) age = 25 ✓ (CORRECT) C) var age = 25 D) age := 25 E) let age = 25 RATIONALE: Python uses dynamic typing, so variables are declared simply by assigning a value. No keyword (like int, var, or let) or type declaration is needed. The correct syntax is age =
18. What is the correct syntax for an if statement in Python? A) if (x > 5) { B) if x > 5: ✓ (CORRECT) C) if x > 5 then
21. Which operator is used to check if two values are not equal in Python? A) != ✓ (CORRECT) B) <> C) !== D) !=! E) =! RATIONALE: Python uses != for the not-equal comparison operator. It returns True if the operands are not equal. 22. What is the output of print(5 != 3)? A) 1 B) 0 C) True ✓ (CORRECT) D) False E) Error RATIONALE: 5 is not equal to 3, so the != operator returns True. 23. Which keyword is used to define a function in Python? A) function B) def ✓ (CORRECT) C) define D) func E) procedure RATIONALE: The def keyword is used to define functions in
Python. function, define, and func are not valid keywords in Python for function definition.
24. Which of the following correctly creates a Python list? A) list = (1, 2, 3) B) list = [1, 2, 3] ✓ (CORRECT) C) list = {1, 2, 3} D) list = <1, 2, 3> E) list = 1, 2, 3 RATIONALE: In Python, lists are created using square brackets []. Parentheses create tuples, curly braces create sets or dictionaries, and angle brackets are not used for Python data structures. 25. What is the output of print(len([1, 2, 3, 4]))? A) 3 B) 4 ✓ (CORRECT) C) 5 D) [1, 2, 3, 4] E) Error RATIONALE: The len() function returns the number of items in a container. The list [1, 2, 3, 4] contains 4 elements, so len() returns 4.
RATIONALE: 5 is an integer literal, so type(5) returns .
29. How do you create an empty dictionary in Python? A) dict = [] B) dict = {} C) dict = () ✓ (CORRECT) (Both B and C are correct depending on context) ✓ (CORRECT) D) dict = set() E) dict = <> RATIONALE: An empty dictionary is created using {}. An empty set requires set(). The question asks specifically for a dictionary, so the correct answer is {}. 30. What is the output of print(2 ** 3)? A) 6 B) 8 ✓ (CORRECT) C) 9 D) 5 E) 4 RATIONALE: 2 ** 3 means 2 raised to the power of 3, which equals 8.
31. Which for loop syntax is correct in Python? A) for (i = 0; i < 5; i++): B) for i in range(5): ✓ (CORRECT) C) for i = 0 to 4: D) for i from 0 to 4: E) foreach i in range(5): RATIONALE: Python uses "for variable in iterable:" syntax. range(5) generates a sequence of numbers from 0 to 4, so the loop iterates 5 times. 32. What does the range(5) function generate? A) [1, 2, 3, 4, 5] B) [0, 1, 2, 3, 4] ✓ (CORRECT) C) [0, 1, 2, 3, 4, 5] D) (0, 1, 2, 3, 4) E) (1, 2, 3, 4, 5) RATIONALE: range(5) generates a sequence of numbers starting from 0 up to but not including 5: 0, 1, 2, 3, 4. 33. What is the output of print(0.1 + 0.2 == 0.3)? A) True B) False ✓ (CORRECT) C) 0. D) Error E) None RATIONALE: Due to floating-point precision limitations in
36. What is the output of print(True and False)? A) True B) False ✓ (CORRECT) C) 1 D) 0 E) Error RATIONALE: The and operator returns True only if both operands are True. Since one operand is False, the result is False. 37. What is the output of print(True or False)? A) True ✓ (CORRECT) B) False C) 1 D) 0 E) Error RATIONALE: The or operator returns True if at least one operand is True. Since one operand is True, the result is True. 38. Which keyword is used to exit a loop prematurely in Python? A) exit B) stop C) break ✓ (CORRECT) D) continue E) return
RATIONALE: The break keyword is used to exit a loop prematurely. The continue keyword skips the current iteration and moves to the next.
39. Which keyword is used to skip the current iteration of a loop in Python? A) exit B) stop C) break D) continue ✓ (CORRECT) E) skip RATIONALE: The continue keyword skips the current iteration of a loop and moves to the next iteration. 40. What is the output of print(5 / 2)? A) 2.5 ✓ (CORRECT) B) 2 C) 2. D) 3 E) 2. RATIONALE: In Python 3, the / operator performs true division and returns a float. 5 / 2 equals 2.5.
"include" (PHP), "using" (C#), and "require" are not Python syntax.
44. Which of the following is a mutable data type in Python? A) tuple B) list ✓ (CORRECT) C) str D) int E) bool RATIONALE: Lists are mutable, meaning their contents can be changed after creation. Tuples, strings, integers, and booleans are immutable. 45. Which of the following is an immutable data type in Python? A) tuple ✓ (CORRECT) B) list C) dict D) set E) array RATIONALE: Tuples are immutable, meaning they cannot be changed after creation. Lists, dictionaries, and sets are mutable.
46. What is the output of print(3 / 3)? A) 1.0 ✓ (CORRECT) B) 1 C) 0 D) 3. E) Error RATIONALE: In Python 3, the / operator always returns a float. 3 divided by 3 equals 1.0. 47. Which operator is used to assign a value to a variable in Python? A) == B) = ✓ (CORRECT) C) := D) <= E) => RATIONALE: The = operator is used for assignment in Python. == is the equality comparison operator. 48. What is the output of print(3 == "3")? A) True B) False ✓ (CORRECT) C) 3 D) Error E) None RATIONALE: The == operator compares both value and