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. VS Code
C. MP3
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. score == 10
B. set score 10
C. 10 = score
D. score = 10

4 What is the data type of 3.14 in Python?

Data types Easy
A. bool
B. str
C. float
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. 14
B. 20
C. 24
D. 9

7 Which Python function displays text on the screen?

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

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

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

9 Which statement imports Python's math module?

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

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

Representing text Easy
A. int
B. str
C. list
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. Angle brackets: <>
B. Parentheses: ()
C. Curly braces: {}
D. Square brackets: []

13 Which data type stores either True or False?

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

14 What does int("7") return?

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

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. 3.0
B. 12
C. 2
D. 4

18 What is PEP 8 mainly concerned with?

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

19 Which structure chooses between two blocks of code?

If-else statement Easy
A. import-from
B. for-in
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. A text editor without extensions
B. A standard Python interpreter only
C. Anaconda distribution
D. The Python documentation website

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. 15
B. 2
C. 8
D. 5

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

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

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

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

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

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

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

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

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

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

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

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

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. tho
C. Python
D. yth

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

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

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

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

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

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

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

String formatting Medium
A. "{name} scored {score}"
B. f"name scored score"
C. f"{name} scored {score}"
D. format("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. open calculation.py
B. python calculation.py
C. execute Python calculation.py
D. run 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 shorter names such as x and y
B. Place all statements on one line
C. Use descriptive names and small functions
D. Remove comments and blank lines

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

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

40 Which expression evaluates to True?

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

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, 3], b == [1, 2]
D. a == [1, 2], b == [1, 2]

44 Which expression evaluates to a value of type float?

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

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

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

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

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

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

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

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

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. 2 1
B. 1 1
C. 2 2
D. 1 2

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

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

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

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

51 What is the result of the following expression?

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

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

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. [2, 3, 9] [2, 3, 9]
C. [1, 2, 3, 4] [1, 2, 3, 4, 9]
D. [1, 2, 3, 4] [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 and y are immutable, while z preserves insertion duplicates
C. x is immutable, y is mutable, and z is unordered and unique
D. x, y, and z preserve duplicates and support indexing

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

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

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

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

56 What is printed by this code?

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

String formatting Hard
A. name: score
B. Ada: 2.3333333333333335
C. Ada: 2.3
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. main
D. The absolute file path

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. Validate inputs near the function boundary and raise a specific error
B. Catch every exception and return None
C. Suppress the failure with a broad try block
D. Duplicate the function to handle each possible input

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,\n fourth):
C. def calculate_total(first,second,third,fourth):
D. def calculate_total(first, second, third, 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 not score < 60 else "fail"
B. if score >= 60: status = "pass"; else: status = "fail"
C. status = "pass" if score >= 60 else "fail"
D. status = ["fail", "pass"][score >= 60]