Unit 1: Python Environment Setup and Basics - Practice Quiz

CSR101 — Python Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which tool is commonly used to write and run Python code?

Installing Python and IDEs (Anaconda, Jupyter, VS Code) Easy
A. HTML
B. MP3
C. VS Code
D. JPEG

2 Which symbol starts a comment in Python?

Python syntax Easy
A. //
B. /*
C. --
D. #

3 Which statement assigns the value to a variable named score?

Variables Easy
A. set score 10
B. 10 = score
C. score == 10
D. score = 10

4 What is the data type of 3.14 in Python?

Data types Easy
A. bool
B. float
C. str
D. int

5 Which operator is used for multiplication in Python?

Operators Easy
A. %
B. *
C. ^
D. x

6 What is the value of the expression 2 + 3 * 4?

Expressions Easy
A. 20
B. 14
C. 24
D. 9

7 Which Python function displays text on the screen?

Input/output Easy
A. input()
B. print()
C. showtext()
D. display()

8 Which keyword is commonly used to bring a module into a Python program?

Module basics Easy
A. include
B. using
C. import
D. module

9 Which statement imports Python's math module?

Math module Easy
A. use math
B. include math
C. import math
D. math.load()

10 Which data type is used to represent text in Python?

Representing text Easy
A. int
B. list
C. str
D. float

11 Which is a valid Python string?

String basics Easy
A. [Hello]
B. "Hello"
C. {Hello}
D. Hello

12 Which symbol is used to create a list in Python?

List Easy
A. Parentheses: ()
B. Angle brackets: <>
C. Curly braces: {}
D. Square brackets: []

13 Which data type stores either True or False?

Common data types summary Easy
A. float
B. bool
C. list
D. str

14 What does int("7") return?

Type conversions Easy
A. The Boolean True
B. The string "7"
C. The float 7.0
D. The integer 7

15 What decimal number is represented by the binary number 101?

Binary numbers Easy
A. 4
B. 6
C. 5
D. 3

16 Which is an f-string in Python?

String formatting Easy
A. string("Hello", name)
B. format Hello name
C. f"Hello {name}"
D. "f Hello name"

17 What is the result of entering 6 / 2 in the Python shell?

Using Python shell as a calculator and running simple scripts Easy
A. 4
B. 3.0
C. 2
D. 12

18 What is PEP 8 mainly concerned with?

PEP 8 Easy
A. Creating image files
B. Managing internet accounts
C. Python style guidelines
D. Installing computer hardware

19 Which structure chooses between two blocks of code?

If-else statement Easy
A. for-in
B. import-from
C. if-else
D. def-return

20 Which operator checks whether two values are equal?

Equality and relational operators Easy
A. =>
B. !=
C. =
D. ==

21 A student wants an environment that includes Python, commonly used scientific libraries, and a package manager with minimal separate setup. Which choice is most suitable?

Installing Python and IDEs (Anaconda, Jupyter, VS Code) Medium
A. The Python documentation website
B. A text editor without extensions
C. Anaconda distribution
D. A standard Python interpreter only

22 Which code correctly defines a function that returns the square of its argument?

Python syntax Medium
A. def square(x): return x ** 2
B. def square(x) return x ** 2
C. function square(x): return x ** 2
D. define square(x): x ** 2

23 After executing a = 5 and a = a + 3, what value does a contain?

Variables Medium
A. 5
B. 8
C. 15
D. 2

24 What is the data type of the value produced by 7 / 2 in Python 3?

Data types Medium
A. str
B. float
C. int
D. complex

25 What is the value of 17 // 5 + 17 % 5?

Operators Medium
A. 7
B. 5
C. 3
D. 8

26 What is the result of the expression 2 * (3 + 4) ** 2?

Expressions Medium
A. one hundred forty-four
B. fifty-six
C. one hundred
D. ninety-eight

27 What is displayed by this code if the user enters 12? age = input("Age: ")\nprint(age + " years")

Input/output Medium
A. 24 years
B. 12 years
C. age years
D. A type error occurs

28 Which statement correctly imports only the sqrt function from the math module?

Module basics Medium
A. include math.sqrt
B. using math.sqrt
C. from math import sqrt
D. import sqrt from math

29 What value is returned by math.ceil(4.2) after import math?

Math module Medium
A. 4
B. 5
C. 6
D. 4.2

30 Why does Python support Unicode strings?

Representing text Medium
A. To represent characters from many writing systems
B. To convert numbers automatically into text
C. To prevent strings from being indexed
D. To make every string use one byte

31 What is the result of "Python"[1:4]?

String basics Medium
A. Pyt
B. yth
C. tho
D. Python

32 What is the value of items after executing items = [2, 4, 6]; items.append(8)?

List Medium
A. [2, 4, 6, 8]
B. [8, 2, 4, 6]
C. [2, 4, 8]
D. [2, 4, 6]

33 What is the result of int("3.8")?

Type conversions Medium
A. 4
B. 3
C. 3.8
D. A valid integer conversion

34 What decimal value does the binary literal 0b1011 represent?

Binary numbers Medium
A. 13
B. 11
C. 9
D. 10

35 Which f-string displays name = "Mira" and score = 92 as Mira scored 92?

String formatting Medium
A. format("name scored score")
B. "{name} scored {score}"
C. f"name scored score"
D. f"{name} scored {score}"

36 A file named calculation.py contains print(6 * 7). Which command runs it from a terminal where Python is available?

Using Python shell as a calculator and running simple scripts Medium
A. python calculation.py
B. run calculation.py
C. open calculation.py
D. execute Python calculation.py

37 Which function definition follows the usual PEP 8 spacing convention?

PEP 8 Medium
A. def add(a,b):
B. def add(a , b) :
C. def add (a, b):
D. def add(a, b):

38 Which change most improves the readability of code that calculates a total price?

Code readability Medium
A. Use descriptive names and small functions
B. Use shorter names such as x and y
C. Remove comments and blank lines
D. Place all statements on one line

39 What does this code print when temperature = 15? if temperature > 20:\n print("warm")\nelse:\n print("cool")

If-else statement Medium
A. 15
B. warm
C. cool
D. Nothing

40 Which expression evaluates to True?

Equality and relational operators Medium
A. 5 < 3
B. 5 == "5"
C. 5 != 6
D. 5 = 5

41 A script runs correctly from a terminal using one Python interpreter, but VS Code reports ModuleNotFoundError for a package installed with pip. Which action most directly diagnoses the mismatch?

Installing Python and IDEs (Anaconda, Jupyter, VS Code) Hard
A. Compare python -c "import sys; print(sys.executable)" with the selected interpreter
B. Convert the script into a Jupyter notebook
C. Install the package again without changing interpreters
D. Restart VS Code and rerun the script

42 What is printed by the following code?

PYTHON
x = 10
if x > 5:
    y = x * 2
    if y == 20:
        print("A")
    else:
        print("B")
else:
    print("C")

Python syntax Hard
A. B
B. C
C. An indentation error
D. A

43 After executing the following code, what are the values of a and b?

PYTHON
a = [1, 2]
b = a
a += [3]

Variables Hard
A. a == [3], b == [1, 2]
B. a == [1, 2, 3], b == [1, 2, 3]
C. a == [1, 2], b == [1, 2]
D. a == [1, 2, 3], b == [1, 2]

44 Which expression evaluates to a value of type float?

Data types Hard
A. type(7 % 2)
B. type(7 / 2)
C. type(7 // 2)
D. type(7 ** 0)

45 What is the value of -7 // 3 in Python?

Operators Hard
A. -3
B. 2
C. -2
D. 1

46 What does the expression 2 ** 3 ** 2 evaluate to?

Expressions Hard
A. 256
B. 64
C. 36
D. 512

47 What is printed when the user enters 08 at the prompt?

PYTHON
value = input("Number: ")
print(value + "1")

Input/output Hard
A. A TypeError
B. 9
C. 81
D. 081

48 Assume tools.py contains count = 1 and def increment(): global count; count += 1. What is printed?

PYTHON
import tools
from tools import count

tools.increment()
print(count, tools.count)

Module basics Hard
A. 1 1
B. 2 2
C. 2 1
D. 1 2

49 Which statement correctly describes math.isclose(0.1 + 0.2, 0.3)?

Math module Hard
A. It raises an error because decimal literals are approximate
B. It returns False because floating-point values are never equal
C. It returns True using tolerance-based comparison
D. It converts both operands to integers before comparing

50 A UTF-8 encoded file begins with the bytes 72 C3 A9. Which text does this byte sequence represent?

Representing text Hard
A.
B. Hé
C. éH
D. A decoding error

51 What is the result of the following expression?

PYTHON
"  Python\n".strip().lower()[::-1]

String basics Hard
A. "nohtyP"
B. " nohtyp\n"
C. "nohtyp"
D. "Python"

52 What is printed?

PYTHON
items = [1, 2, 3, 4]
result = items[1:3]
result.append(9)
print(items, result)

List Hard
A. [1, 2, 3, 4, 9] [2, 3, 9]
B. [1, 2, 3, 4] [1, 2, 3, 4, 9]
C. [1, 2, 3, 4] [2, 3, 9]
D. [2, 3, 9] [2, 3, 9]

53 Which statement is correct about the following objects?

PYTHON
x = (1, 2)
y = [1, 2]
z = {1, 2}

Common data types summary Hard
A. x is unordered, y is hashable, and z supports integer indexing
B. x, y, and z preserve duplicates and support indexing
C. x and y are immutable, while z preserves insertion duplicates
D. x is immutable, y is mutable, and z is unordered and unique

54 What is the result of int(float("3.9"))?

Type conversions Hard
A. 4
B. A ValueError
C. 3.9
D. 3

55 What is the decimal value of the Python expression 0b101101 & 0b011011?

Binary numbers Hard
A. 25
B. 9
C. 11
D. 45

56 What is printed by this code?

PYTHON
name = "Ada"
score = 7 / 3
print(f"{name}: {score:.2f}")

String formatting Hard
A. Ada: 2.3333333333333335
B. Ada: 2.3
C. name: score
D. Ada: 2.33

57 A file contains print(__name__) and is executed directly with python file.py. What is normally printed?

Using Python shell as a calculator and running simple scripts Hard
A. file.py
B. main
C. The absolute file path
D. __main__

58 A function sometimes fails because a caller passes malformed data. Which design best improves maintainability and debugging?

Introduction to software development best practices Hard
A. Suppress the failure with a broad try block
B. Validate inputs near the function boundary and raise a specific error
C. Duplicate the function to handle each possible input
D. Catch every exception and return None

59 Which revision best follows PEP 8 for a function definition with a long parameter list?

PEP 8 Hard
A. def calculate_total(first, second, third, fourth,):
B. def calculate_total(first, second, third, fourth):
C. def calculate_total(first,second,third,fourth):
D. def calculate_total(first, second, third,\n fourth):

60 Which implementation is most readable and least error-prone for classifying a score?

PYTHON
score = 73

Code readability Hard
A. status = "pass" if score >= 60 else "fail"
B. status = "pass" if not score < 60 else "fail"
C. if score >= 60: status = "pass"; else: status = "fail"
D. status = ["fail", "pass"][score >= 60]