Unit 1 MCQs Python basics
ECAP776 60 questions. Pick an option to check it.
0 of 60 answered 0 right 0 wrong , 60 left
Unit mastery 0% no weak questions yet
-
Question 1 of 60 Introduction Easy
Which file extension is commonly used for Python source files?
-
Question 2 of 60 Introduction Easy
Which function displays output on the screen in Python?
-
Question 3 of 60 Introduction Easy
Which symbol begins a single-line comment in Python?
-
Question 4 of 60 Introduction Easy
Which function accepts input from the user in Python?
-
Question 5 of 60 Introduction Easy
Which of the following is a valid Python variable name?
-
-
Question 6 of 60 Data types and operators Easy
Which Python data type stores whole numbers?
-
Question 7 of 60 Data types and operators Easy
What is the data type of the value
3.14in Python? -
Question 8 of 60 Data types and operators Easy
Which operator is used for exponentiation in Python?
-
Question 9 of 60 Data types and operators Easy
What is the result of
10 % 3? -
Question 10 of 60 Data types and operators Easy
Which operator checks whether two values are equal?
-
Question 11 of 60 Control statements Easy
Which keyword begins a conditional statement in Python?
-
Question 12 of 60 Control statements Easy
Which keyword provides an alternative when an
ifcondition is false? -
Question 13 of 60 Control statements Easy
Which loop is commonly used to iterate over a sequence in Python?
-
Question 14 of 60 Control statements Easy
Which statement immediately exits the nearest loop?
-
Question 15 of 60 Control statements Easy
Which statement skips the rest of the current loop iteration?
-
Question 16 of 60 Functions Easy
Which keyword is used to define a function in Python?
-
Question 17 of 60 Functions Easy
What is the purpose of the
returnstatement in a function? -
Question 18 of 60 Functions Easy
In
def greet(name):, what isname? -
Question 19 of 60 Functions Easy
How do you call a function named
showthat takes no arguments? -
Question 20 of 60 Functions Easy
Which built-in function returns the number of items in a list?
-
Question 21 of 60 Introduction Medium
What is printed by the following code?
x = 10
x = "10"
print(x * 2) -
Question 22 of 60 Introduction Medium
A file named
tools.pycontains:
print("loaded")
if __name__ == "__main__":
print("running")
What is printed when another program executesimport tools? -
Question 23 of 60 Introduction Medium
What is the output of this simultaneous assignment?
a, b = 2, 3
a, b = b, a + b
print(a, b) -
Question 24 of 60 Introduction Medium
What does this program print?
total = 4
Total = 7
TOTAL = total + Total
print(TOTAL) -
Question 25 of 60 Data types and operators Medium
What is printed by
print(type((5,)).__name__, type((5)).__name__)? -
Question 26 of 60 Data types and operators Medium
What is the output of
print(-7 // 3, -7 % 3)? -
Question 27 of 60 Data types and operators Medium
What is printed by the following code?
a = [1, 2]
b = a
c = a[:]
b.append(3)
print(c, a) -
Question 28 of 60 Data types and operators Medium
What is the output of this dictionary operation?
d = {"a": 1, "b": 2, "a": 3}
print(len(d), d["a"]) -
Question 29 of 60 Data types and operators Medium
Which set is produced by
{1, 2, 3} & {2, 3, 4} | {4, 5}? -
Question 30 of 60 Data types and operators Medium
What value is printed by
print(-2 ** 2 + 2 ** 3)? -
Question 31 of 60 Control statements Medium
What is printed by the following loop?
total = 0
for n in range(2, 10, 3):
total += n
print(total) -
Question 32 of 60 Control statements Medium
Which letter is printed by this conditional?
x = 8
if x % 2 == 0 and x > 10:
print("A")
elif x % 2 == 0 or x > 10:
print("B")
else:
print("C") -
Question 33 of 60 Control statements Medium
What value is printed after this loop?
n = 20
count = 0
while n > 1:
n //= 2
count += 1
print(count) -
Question 34 of 60 Control statements Medium
What is the final value of
result?
result = []
for n in range(2, 10):
if n % 3 == 0:
continue
if n > 7:
break
result.append(n) -
Question 35 of 60 Control statements Medium
What is printed by these nested loops?
count = 0
for i in range(1, 4):
for j in range(1, 4):
if i == j:
continue
count += 1
print(count) -
Question 36 of 60 Functions Medium
What is printed by the following code?
def add_item(item, items=[]):
items.append(item)
return items
print(add_item(1))
print(add_item(2)) -
Question 37 of 60 Functions Medium
What is the output of this program?
x = 10
def change():
x = 3
return x
print(change(), x) -
Question 38 of 60 Functions Medium
What value is returned by
calculate(3, 4, 5, 6)?
def calculate(a, b=2, *numbers):
return a + b + sum(numbers) -
Question 39 of 60 Functions Medium
What is printed by this function call?
def divide_parts(n):
return n // 2, n % 2
q, r = divide_parts(7)
print(q, r) -
Question 40 of 60 Functions Medium
What is the value of
orderedafter this statement?
words = ["pear", "fig", "apple", "kiwi"]
ordered = sorted(words, key=lambda word: (len(word), word)) -
Question 41 of 60 Introduction Hard
What is printed by the following code?
Pythona = [0, 0] i = 0 i, a[i] = 1, 7 print(a, i) -
Question 42 of 60 Introduction Hard
Assuming no future imports, what is printed?
Pythondef f(x: int = '3') -> int: return x * 2 print(f(), f(4)) -
Question 43 of 60 Introduction Hard
What happens when this code is executed?
Pythonx = 10 def f(flag): if flag: x = 20 return x print(f(False)) -
Question 44 of 60 Introduction Hard
In Python 3.10 or later, what is printed by this module-level code?
Pythonx = 100 s = [x := x + i for i in range(3)] print(x, s, 'i' in globals()) -
Question 45 of 60 Introduction Hard
A file named
m.pycontains onlyprint(__name__). What does it print when run directly, and what does it print when first imported asmby another script? -
Question 46 of 60 Data types and operators Hard
What is printed by the following code?
Pythonx = [1, 2] y = x x += [3] z = x x = x + [4] print(y, z, x, y is z, z is x) -
Question 47 of 60 Data types and operators Hard
What is printed?
Pythonresult = 0 or [] or 'py' and 5 print(result, type(result).__name__) -
Question 48 of 60 Data types and operators Hard
What is printed by this dictionary code?
Pythond = {True: 'A', 1: 'B', 1.0: 'C'} print(len(d), list(d.keys()), d[1]) -
Question 49 of 60 Data types and operators Hard
What is printed by these slices?
Pythona = [0, 1, 2, 3, 4, 5] print(a[5:0:-2], a[::-2]) -
Question 50 of 60 Data types and operators Hard
What exact text is printed?
Pythondef f(v): print(v, end='') return v print(f(3) < f(2) < f(1)) -
Question 51 of 60 Control statements Hard
What exact text is printed?
Pythonfor i in range(3): try: if i == 1: continue print(i, end='') finally: print('F', end='') -
Question 52 of 60 Control statements Hard
What is printed?
Pythonn = 3 while n: n -= 1 if n == 1: break else: print('E', end='') print(n) -
Question 53 of 60 Control statements Hard
What exact text is printed?
Pythonfor i in range(4): for j in range(4): if i * j > 2: break else: print(i, end='') -
Question 54 of 60 Control statements Hard
What is printed by the following code?
Pythondef g(x): try: r = 10 // x except ZeroDivisionError: r = 0 else: r += 1 finally: r *= 2 return r print(g(2), g(0)) -
Question 55 of 60 Control statements Hard
What is printed by this comprehension?
Pythonprint([i for i in range(6) if i % 2 if i % 3]) -
Question 56 of 60 Functions Hard
What is printed?
Pythondef f(x, acc=[]): acc += [x] return acc a = f(1) b = f(2, []) c = f(3) print(a, b, c, a is c) -
Question 57 of 60 Functions Hard
What is printed by these functions?
Pythonfuncs = [] for i in range(3): funcs.append(lambda x=i: x + i) i = 10 print([f() for f in funcs]) -
Question 58 of 60 Functions Hard
In Python 3.10 or later, which call raises
TypeError?
Pythondef f(a, /, b=2, *, c=3): return a + b + c -
Question 59 of 60 Functions Hard
What is printed after applying these decorators?
Pythondef deco(tag): def outer(fn): def inner(): return tag + fn() + tag return inner return outer @deco('A') @deco('B') def f(): return 'X' print(f()) -
Question 60 of 60 Functions Hard
What is printed by this generator code?
Pythondef gen(): yield 1 return 7 g = gen() a = next(g) try: next(g) except StopIteration as e: b = e.value print(a, b)
That's unit 1
Answer a few questions and your score shows up here.
Nearly through. Did unit 1 of ECAP776 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 1 of ECAP776 save you a night before the exam?
Then you can help keep it free for the next batch. 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.