0% found this document useful (0 votes)
2 views10 pages

B.S. (DS) Python T4

The document contains a series of multiple-choice questions (MCQs) related to Python programming, covering topics such as variable assignment, data types, functions, modules, file handling, exceptions, and graphics. Each question is followed by the correct answer, providing a comprehensive overview of essential Python concepts. The document includes a total of 50 MCQs, structured into different modules and units.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

B.S. (DS) Python T4

The document contains a series of multiple-choice questions (MCQs) related to Python programming, covering topics such as variable assignment, data types, functions, modules, file handling, exceptions, and graphics. Each question is followed by the correct answer, providing a comprehensive overview of essential Python concepts. The document includes a total of 50 MCQs, structured into different modules and units.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1. Which of the following is used to assign a value to a variable in Python?

A. ==
B. =
C. :=
D. =>
✅ Correct Answer: B

2. What is the correct way to start a single-line comment in Python?


A. /* comment */
B. // comment
C. # comment
D. -- comment
✅ Correct Answer: C

3. Which data type is used to represent decimal values in Python?


A. int
B. str
C. float
D. bool
✅ Correct Answer: C

4. What will be the output of 5 + 3 * 2 in Python?


A. 16
B. 11
C. 13
D. 10
✅ Correct Answer: B

5. Which operator is used to compare the memory locations of two objects?


A. ==
B. is
C. !=
D. in
✅ Correct Answer: B

6. What keyword is used for defining a block in Python?


A. begin
B. start
C. indent
D. Indentation (space or tab)
✅ Correct Answer: D
7. Which of the following loops in Python includes an else part?
A. do...while
B. for
C. while
D. Both B and C
✅ Correct Answer: D

UNIT-2: DATA STRUCTURES AND FUNCTIONS

8. Which data structure in Python is immutable?


A. List
B. Set
C. Tuple
D. Dictionary
✅ Correct Answer: C

9. Which of these will create an empty set?


A. {}
B. []
C. set()
D. ()
✅ Correct Answer: C

10. What will be the output of len("Python")?


A. 5
B. 6
C. 7
D. Error
✅ Correct Answer: B

11. How do you define an anonymous function in Python?


A. define()
B. lambda
C. func()
D. def
✅ Correct Answer: B

12. What is the scope of a variable defined inside a function?


A. Global
B. Static
C. Local
D. Public
✅ Correct Answer: C

13. Which keyword is used to define a function in Python?


A. define
B. def
C. func
D. function
✅ Correct Answer: B

MODULE-2

UNIT-1: MODULES AND FILES

14. Which module is used to work with date and time in Python?
A. datetime
B. calendar
C. os
D. time
✅ Correct Answer: A

15. Which of the following is a correct way to import only the sqrt function from the math module?
A. import math.sqrt
B. from math import sqrt
C. include math.sqrt
D. use math.sqrt()
✅ Correct Answer: B

16. What does the seek() function do in file handling?


A. Closes the file
B. Reads data from a file
C. Writes data to a file
D. Moves the file pointer to a specified location
✅ Correct Answer: D

17. Which module is used for random number generation in Python?


A. random
B. math
C. os
D. sys
✅ Correct Answer: A

UNIT-2: EXCEPTIONS AND GRAPHICS

18. What is the output of try: print(1/0) except: print("Error")?


A. 1
B. Error
C. 0
D. Error message
✅ Correct Answer: B

19. Which block is always executed whether an exception occurs or not?


A. try
B. except
C. else
D. finally
✅ Correct Answer: D

20. Which of the following modules is used for basic graphics in Python?
A. turtle
B. graphics
C. os
D. draw
✅ Correct Answer: A

Let me know if you want these as a formatted PDF or as a printable version, or if you'd like a set of more
advanced MCQs.

2/2

You said:

more mcq

A network error occurred. Please check your connection and try again. If this issue persists please contact us
through our help center at help.openai.com.
ChatGPT said:

Sure! Here's another set of MCQs based on your Python Programming Syllabus (MODULE-1 and
MODULE-2):
✅ MODULE-1

UNIT-1: INTRODUCTION

1. What will be the data type of the result of 4 + 3.0 in Python?


A. int
B. float
C. complex
D. string
✅ Correct Answer: B

**2. Which of the following is not a valid Python keyword?

2/2

You said:

i want total of 50 mcq from the above syllabus


ChatGPT said:

Great! Here's Part 2 of the Python Programming MCQs, continuing from the syllabus you provided. You
already have 20 questions. Below are Questions 21 to 50, completing the set of 50 MCQs from Module 1 & 2
of your syllabus.

📘 MCQs 21 to 50

MODULE-1 | UNIT-1: INTRODUCTION (continued)

21. Which of the following is NOT a basic data type in Python?


A. float
B. complex
C. boolean
D. character
✅ Correct Answer: D

22. Which of the following is a valid variable name in Python?


A. 2name
B. name_1
C. class
D. @name
✅ Correct Answer: B

23. The expression True and False or True evaluates to:


A. True
B. False
C. Error
D. None
✅ Correct Answer: A

24. Which operator is used to perform bitwise AND in Python?


A. &
B. &&
C. and
D. @
✅ Correct Answer: A

25. What will be the output of: 'abc' * 2?


A. abcabc
B. abc2
C. Error
D. aabbcc
✅ Correct Answer: A

26. The pass statement in Python is used to:


A. Skip a value
B. Terminate a loop
C. Do nothing
D. Raise an error
✅ Correct Answer: C

27. What is the output of: bool(0) in Python?


A. True
B. False
C. 0
D. None
✅ Correct Answer: B
28. Python scripts have the file extension:
A. .pt
B. .py
C. .ps
D. .txt
✅ Correct Answer: B

MODULE-1 | UNIT-2: DATA STRUCTURES & FUNCTIONS (continued)

29. Which of the following is a mutable data structure?


A. String
B. Tuple
C. List
D. Frozenset
✅ Correct Answer: C

30. What is the output of type({}) in Python?


A. list
B. tuple
C. dict
D. set
✅ Correct Answer: C

31. What is the correct syntax for list comprehension to create a list of squares from 1 to 5?
A. [x^2 for x in range(1,6)]
B. [x**2 for x in range(1,6)]
C. (x**2 for x in range(1,6))
D. {x**2 for x in range(1,6)}
✅ Correct Answer: B

32. Which keyword is used to return a value from a function?


A. break
B. yield
C. return
D. pass
✅ Correct Answer: C

**33. What will be the output of the following code?

python
CopyEdit
def add(a, b=2):
return a + b
print(add(3))
```**
A. 2
B. 3
C. 5
D. Error
✅ **Correct Answer: C**

---

**34. What is the output of a recursive function without a base case?**


A. Compiles successfully
B. Infinite loop
C. RecursionError
D. None
✅ **Correct Answer: C**

---

**35. What type of function is `lambda` in Python?**


A. Named function
B. Recursive function
C. Anonymous function
D. Generator
✅ **Correct Answer: C**

---

**36. What is the scope of a variable defined inside a function but outside any loop or
conditional block?**
A. Local
B. Global
C. Static
D. Class
✅ **Correct Answer: A**

---

#### **MODULE-2 | UNIT-1: MODULES & FILE PROCESSING**

**37. Which of these is not a built-in Python module?**


A. `random`
B. `itertools`
C. `numpy`
D. `math`
✅ **Correct Answer: C**

---

**38. Which function is used to get command-line arguments in Python?**


A. `os.argv`
B. `sys.args`
C. `sys.argv`
D. `os.args`
✅ **Correct Answer: C**

---

**39. What does the `os.rename()` function do?**


A. Reads a file
B. Deletes a file
C. Renames a file
D. Copies a file
✅ **Correct Answer: C**

---

**40. Which method is used to read the entire content of a file at once?**
A. `readfile()`
B. `read()`
C. `readline()`
D. `readlines()`
✅ **Correct Answer: B**

---

**41. What does `with open("file.txt", "r") as f:` do?**


A. Writes to the file
B. Closes the file
C. Opens the file for reading and auto-closes it
D. Deletes the file
✅ **Correct Answer: C**

---

**42. Which file mode is used to write and overwrite a file?**


A. `r`
B. `a`
C. `w`
D. `x`
✅ **Correct Answer: C**

---

**43. Which module is used to draw shapes in Python?**


A. `canvas`
B. `turtle`
C. `paint`
D. `graphics`
✅ **Correct Answer: B**

---

**44. What does `tell()` function return in file handling?**


A. Current file name
B. File length
C. Current file position
D. Total lines
✅ **Correct Answer: C**

---

#### **MODULE-2 | UNIT-2: EXCEPTIONS & GRAPHICS**

**45. What happens if you don’t handle an exception in Python?**


A. Program continues
B. Program crashes
C. Program skips that line
D. Compiler handles it
✅ **Correct Answer: B**

---
**46. Which keyword is used to raise a custom exception in Python?**
A. `throw`
B. `except`
C. `raise`
D. `error`
✅ **Correct Answer: C**

---

**47. What is the output of:


```python
try:
print(1/0)
except ZeroDivisionError:
print("Division by zero")
```**
A. 1
B. 0
C. Error
D. Division by zero
✅ **Correct Answer: D**

---

**48. What is the RGB color code for red?**


A. `(255, 0, 0)`
B. `(0, 255, 0)`
C. `(0, 0, 255)`
D. `(255, 255, 255)`
✅ **Correct Answer: A**

---

**49. Which method is used to fill color in Turtle graphics?**


A. `fillcolor()`
B. `colorfill()`
C. `setcolor()`
D. `fill()`
✅ **Correct Answer: A**

---

**50. Which of the following modules is useful for image processing in Python?**
A. `PIL`
B. `turtle`
C. `math`
D. `numpy`
✅ **Correct Answer: A**

You might also like