Unit 1: Python Environment Setup and Basics - Practice Quiz
1 Which tool is commonly used to write and run Python code?
2 Which symbol starts a comment in Python?
3
Which statement assigns the value to a variable named score?
4
What is the data type of 3.14 in Python?
bool
float
str
int
5 Which operator is used for multiplication in Python?
%
*
^
x
6
What is the value of the expression 2 + 3 * 4?
7 Which Python function displays text on the screen?
input()
print()
showtext()
display()
8 Which keyword is commonly used to bring a module into a Python program?
include
using
import
module
9 Which statement imports Python's math module?
use math
include math
import math
math.load()
10 Which data type is used to represent text in Python?
int
list
str
float
11 Which is a valid Python string?
[Hello]
"Hello"
{Hello}
Hello
12 Which symbol is used to create a list in Python?
()
<>
{}
[]
13
Which data type stores either True or False?
float
bool
list
str
14
What does int("7") return?
True
"7"
7.0
7
15
What decimal number is represented by the binary number 101?
16 Which is an f-string in Python?
string("Hello", name)
format Hello name
f"Hello {name}"
"f Hello name"
17
What is the result of entering 6 / 2 in the Python shell?
4
3.0
2
12
18 What is PEP 8 mainly concerned with?
19 Which structure chooses between two blocks of code?
for-in
import-from
if-else
def-return
20 Which operator checks whether two values are equal?
=>
!=
=
==
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?
22 Which code correctly defines a function that returns the square of its argument?
23
After executing a = 5 and a = a + 3, what value does a contain?
24
What is the data type of the value produced by 7 / 2 in Python 3?
str
float
int
complex
25
What is the value of 17 // 5 + 17 % 5?
26
What is the result of the expression 2 * (3 + 4) ** 2?
27
What is displayed by this code if the user enters 12? age = input("Age: ")\nprint(age + " years")
24 years
12 years
age years
28
Which statement correctly imports only the sqrt function from the math module?
include math.sqrt
using math.sqrt
from math import sqrt
import sqrt from math
29
What value is returned by math.ceil(4.2) after import math?
30 Why does Python support Unicode strings?
31
What is the result of "Python"[1:4]?
Pyt
yth
tho
Python
32
What is the value of items after executing items = [2, 4, 6]; items.append(8)?
[2, 4, 6, 8]
[8, 2, 4, 6]
[2, 4, 8]
[2, 4, 6]
33
What is the result of int("3.8")?
34
What decimal value does the binary literal 0b1011 represent?
35
Which f-string displays name = "Mira" and score = 92 as Mira scored 92?
36
A file named calculation.py contains print(6 * 7). Which command runs it from a terminal where Python is available?
python calculation.py
run calculation.py
open calculation.py
execute Python calculation.py
37 Which function definition follows the usual PEP 8 spacing convention?
def add(a,b):
def add(a , b) :
def add (a, b):
def add(a, b):
38 Which change most improves the readability of code that calculates a total price?
x and y
39
What does this code print when temperature = 15? if temperature > 20:\n print("warm")\nelse:\n print("cool")
15
warm
cool
40
Which expression evaluates to True?
5 < 3
5 == "5"
5 != 6
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?
python -c "import sys; print(sys.executable)" with the selected interpreter
42
What is printed by the following code?
x = 10
if x > 5:
y = x * 2
if y == 20:
print("A")
else:
print("B")
else:
print("C")
B
C
A
43
After executing the following code, what are the values of a and b?
a = [1, 2]
b = a
a += [3]
a == [3], b == [1, 2]
a == [1, 2, 3], b == [1, 2, 3]
a == [1, 2], b == [1, 2]
a == [1, 2, 3], b == [1, 2]
44
Which expression evaluates to a value of type float?
type(7 % 2)
type(7 / 2)
type(7 // 2)
type(7 ** 0)
45
What is the value of -7 // 3 in Python?
-3
2
-2
1
46
What does the expression 2 ** 3 ** 2 evaluate to?
256
64
36
512
47
What is printed when the user enters 08 at the prompt?
value = input("Number: ")
print(value + "1")
TypeError
9
81
081
48
Assume tools.py contains count = 1 and def increment(): global count; count += 1. What is printed?
import tools
from tools import count
tools.increment()
print(count, tools.count)
1 1
2 2
2 1
1 2
49
Which statement correctly describes math.isclose(0.1 + 0.2, 0.3)?
False because floating-point values are never equal
True using tolerance-based comparison
50
A UTF-8 encoded file begins with the bytes 72 C3 A9. Which text does this byte sequence represent?
Hé
Hé
éH
51
What is the result of the following expression?
" Python\n".strip().lower()[::-1]
"nohtyP"
" nohtyp\n"
"nohtyp"
"Python"
52
What is printed?
items = [1, 2, 3, 4]
result = items[1:3]
result.append(9)
print(items, result)
[1, 2, 3, 4, 9] [2, 3, 9]
[1, 2, 3, 4] [1, 2, 3, 4, 9]
[1, 2, 3, 4] [2, 3, 9]
[2, 3, 9] [2, 3, 9]
53
Which statement is correct about the following objects?
x = (1, 2)
y = [1, 2]
z = {1, 2}
x is unordered, y is hashable, and z supports integer indexing
x, y, and z preserve duplicates and support indexing
x and y are immutable, while z preserves insertion duplicates
x is immutable, y is mutable, and z is unordered and unique
54
What is the result of int(float("3.9"))?
4
ValueError
3.9
3
55
What is the decimal value of the Python expression 0b101101 & 0b011011?
25
9
11
45
56
What is printed by this code?
name = "Ada"
score = 7 / 3
print(f"{name}: {score:.2f}")
Ada: 2.3333333333333335
Ada: 2.3
name: score
Ada: 2.33
57
A file contains print(__name__) and is executed directly with python file.py. What is normally printed?
file.py
main
__main__
58 A function sometimes fails because a caller passes malformed data. Which design best improves maintainability and debugging?
try block
None
59 Which revision best follows PEP 8 for a function definition with a long parameter list?
def calculate_total(first, second, third, fourth,):
def calculate_total(first, second, third, fourth):
def calculate_total(first,second,third,fourth):
def calculate_total(first, second, third,\n fourth):
60
Which implementation is most readable and least error-prone for classifying a score?
score = 73
status = "pass" if score >= 60 else "fail"
status = "pass" if not score < 60 else "fail"
if score >= 60: status = "pass"; else: status = "fail"
status = ["fail", "pass"][score >= 60]
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →