INF 303 Python Practice Exam, Exams of Technology

This certification assesses knowledge of Python programming. Topics include data types, control structures, functions, object-oriented programming, libraries, and basic scripting for automation. Candidates gain skills to develop Python-based applications and solve programming problems effectively.

Typology: Exams

2024/2025

Available from 10/14/2025

anil-kumar-jain-1
anil-kumar-jain-1 🇮🇳

2.9

(15)

27K documents

1 / 161

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
INF 303 Python Exam
Question 1. What will happen if you do not use consistent indentation
in a block of Python code?
A) The code will run but may produce wrong results
B) The code will be ignored
C) Python will raise an IndentationError
D) Python will automatically fix the indentation
Answer: C
Explanation: Python requires consistent indentation to define code
blocks; inconsistent indentation will result in an IndentationError.
Question 2. Which character(s) start a single-line comment in Python?
A) //
B) #
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
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download INF 303 Python Practice Exam and more Exams Technology in PDF only on Docsity!

Question 1. What will happen if you do not use consistent indentation in a block of Python code? A) The code will run but may produce wrong results B) The code will be ignored C) Python will raise an IndentationError D) Python will automatically fix the indentation Answer: C Explanation: Python requires consistent indentation to define code blocks; inconsistent indentation will result in an IndentationError. Question 2. Which character(s) start a single-line comment in Python? A) // B) #

C) /*

D) --

Answer: B Explanation: Single-line comments in Python start with the hash (#) character. Question 3. How do you execute a Python script file named "script.py" in the terminal? A) python script.py B) run script.py C) start script.py D) execute script.py Answer: A

A) _counter B) age C) 2age D) name Answer: C Explanation: Variable names cannot start with a number. Question 6. What is the result of 3 + 2 * 2? A) 10 B) 7 C) 9 D) 12 Answer: B

Explanation: Multiplication has higher precedence; 2*2=4, then 3+4=7. Question 7. Which function is used to change the type of a value to a string? A) cast() B) str() C) string() D) toString() Answer: B Explanation: str() converts a value to its string representation. Question 8. What will print(type(5.0)) output? A) <class 'int'>

Explanation: // performs integer (floor) division, discarding the decimal part. Question 10. What is the output of print(4 ** 2)? A) 8 B) 16 C) 6 D) 4 Answer: B Explanation: ** is the exponentiation operator; 4**2 means 4 to the power of 2, which is 16. Question 11. Which of the following is a Boolean value in Python?

A) TRUE

B) True C) Yes D) 1 Answer: B Explanation: The Boolean values are True and False (case-sensitive). Question 12. What is the result of bool("") in Python? A) True B) False C) None D) Error Answer: B

B) python C) Python D) P Y T H O N Answer: A Explanation: upper() returns a new string with all letters capitalized. Question 15. How do you get user input as a string in Python 3? A) input() B) raw_input() C) gets() D) scan() Answer: A Explanation: input() returns user input as a string in Python 3.

Question 16. What will print("apple".replace("a", "o")) display? A) opple B) apple C) oapple D) opplo Answer: A Explanation: replace() replaces all instances of "a" with "o", resulting in 'opple'. Question 17. Which string method removes whitespace from both ends of a string? A) trim()

Question 19. How do you format a string using an f-string? A) "Hello {name}" B) f"Hello {name}" C) format("Hello {name}") D) "Hello".format(name) Answer: B Explanation: f-strings prefix the string with 'f' to allow inline variable interpolation. Question 20. Which of the following expressions gives the last character in the string s? A) s[0]

B) s[-1] C) s[1] D) s[len(s)] Answer: B Explanation: Negative index - 1 accesses the last character of a string. Question 21. What is the result of "hello world".split()? A) ["hello", "world"] B) "hello", "world" C) ['hello world'] D) ('hello', 'world') Answer: A Explanation: split() splits the string at whitespace into a list of words.

C) [1,2,3][4,5]

D) [1,2,3,9]

Answer: A Explanation: The + operator concatenates lists. Question 24. Which method adds an item to the end of a list? A) add() B) append() C) insert() D) push() Answer: B Explanation: append() adds an element to the end of a list.

Question 25. What is the result of: [1,2,3].pop()? A) 1 B) 2 C) 3 D) [1,2,3] Answer: C Explanation: pop() removes and returns the last element of the list. Question 26. What does the method list.sort() do? A) Returns a sorted list B) Sorts the list in place C) Sorts a copy of the list D) Reverses the list

A) A new list with references to the original elements B) A completely independent copy C) A reversed list D) A sorted list Answer: A Explanation: A shallow copy creates a new list object, but elements are references to the same objects as in the source. Question 29. Which of the following creates a list comprehension of squares from 0 to 4? A) [ii for i in range(5)] B) [i^2 for i in 5] C) list(ii for i in range(5))

D) (ii for i in range(5)) Answer: A Explanation: [ii for i in range(5)] uses list comprehension to create a list of squares. Question 30. What is the result of tuple("abc")? A) ("abc") B) ['a', 'b', 'c'] C) ('a', 'b', 'c') D) ('abc',) Answer: C Explanation: tuple("abc") creates a tuple with each character as an element.