































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 /
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 digit. "2nd_place" starts with a number, making it invalid. Variable names can start with a letter or underscore, followed by letters, numbers, or underscores.
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 E) 3. 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. 11. What is the output of print(0 == False)? A) True ✓ (CORRECT) B) False C) 0 D) 1 E) Error RATIONALE: Similar to the previous question, False is equivalent to 0. The expression 0 == False evaluates to True.
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 9.
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 = 25. 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 D) if (x > 5) then E) if x > 5 do RATIONALE: Python uses colons (:) and indentation to define code blocks. The correct syntax for an if statement is "if condition:" followed by an indented block. 19. What is the output of print(5 > 3)? A) 1 B) 0 C) True ✓ (CORRECT) D) False
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. 26. What is the output of print("Hello" + "World")? A) Hello World B) HelloWorld ✓ (CORRECT) C) Hello+World D) Error E) Hello World (with newline) RATIONALE: The + operator concatenates strings. "Hello"
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 binary representation, 0.1 + 0.2 equals 0.30000000000000004, not exactly 0.3, so the comparison returns False. 34. Which function converts a string to an integer? A) str() B) int() ✓ (CORRECT) C) float() D) bool() E) list() RATIONALE: The int() function converts a value to an integer. It can convert a string containing a number to an integer. 35. Which function converts a string to a floating-point number? A) str() B) int() C) float() ✓ (CORRECT)
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.
41. What is the output of print(5 // 2)? A) 2. B) 2 ✓ (CORRECT) C) 2. D) 3 E) 2. RATIONALE: The // operator performs floor division, returning the integer quotient rounded down. 5 divided by 2 equals 2 with a remainder of 1, so floor division returns 2. 42. What is the output of print(5 % 2)? A) 2. B) 2 C) 0 D) 1 ✓ (CORRECT) E) 3 RATIONALE: 5 % 2 returns the remainder of 5 divided by 2, which is 1. 43. Which is the correct way to import a module in Python? A) include math
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)
D) Error E) None RATIONALE: The == operator compares both value and type. 3 is an integer and "3" is a string, so they are not equal, resulting in False.
49. What is the output of print(3 == int("3"))? A) True ✓ (CORRECT) B) False C) 3 D) Error E) None RATIONALE: int("3") converts the string "3" to the integer