NEW
Font size
WorksheetsQuiz3-CC102-MakScie
Total questions: 40
Worksheet time: 40mins
for i in range(2):
for j in range(3):
print(i, j)
How many times will the inner loop execute?
A) 2
B) 3
C) 5
D) 6
for i in range(1, 4):
for j in range(1, i + 1):
print("*", end="")
print()
What is the last line printed?
***
**
*
Blank line
What will be printed?
count = 0
for i in range(2):
for j in range(2):
count += 1
print(count)
A) 2
B) 3
C) 4
D) 1
In nested loops, which loop runs the most?
A) Outer
B) Inner
C) Both equally
D) Depends on code
for i in range(1, 3):
for j in range(1, 4):
if j == 2:
continue
print(i, j)
How many pairs will be printed?
A) 4
B) 5
C) 6
D) 2
x = 10
if x > 5 and x < 15:
print("In range")
Output?
Error
No output
In range
Out of range
and and or are examples of:
Loop keywords
Compound condition operators
Arithmetic operators
Iterators
x, y = 5, 10 if x < y or y < 0: print("Valid")
Valid
Invalid
Nothing
Error
x, y = 5, 10
if x < y or y < 0:
print("Valid")
Output:
True
False
Error
None
Which function definition is correct?
function add(x, y):
def add(x, y)
def add(x, y):
add(x, y): def
def add(a, b=2):
return a + b
print(add(3))
Output?
A) 2
B) 3
C) 5
D) Error
def f(x):
return x * 2
print(f(f(2)))
Output?
2
4
8
Error
def test(a, b):
if a > b and a > 0:
return True
return False
print(test(5, 3))
Output:
True
False
Error
None
for i in range(1, 4):
for j in range(1, 3):
if i == j:
break
print(i, j)
Total printed pairs?
A) 2
B) 3
C) 4
D) 5
for i in range(1, 4):
for j in range(1, 4):
if i == j:
continue
print(i, j)
How many total prints?
6
7
8
9
Which keyword is used to define a function in Python?
define
func
def
function
def multiply(x, y):
return x * y
print(multiply(2, 3) + multiply(3, 2))
Output?
12
10
9
8
What is the output?
def display(n):
while n > 0:
print(n, end=" ")
n -= 1
display(3)
3 2 1
1 2 3
Error
Infinite loop
for i in range(1, 4):
for j in range(1, 4):
if (i + j) % 2 == 0:
print(i, j)
How many pairs printed?
4
5
6
3
def func(a, b):
return a if a > b else b
print(func(3, 5))
Output?
3
5
True
False
A loop inside another loop is called a _________
nested loop
infinite loop
conditional loop
single loop
Compound conditions combine two or more conditions using _________ or _________.
and, or
if, else
true, false
add, subtract
for i in range(2): for j in range(2): print("Hi") This prints “Hi” _________ times.
4
2
6
8
A function that calls itself is known as a _________ function.
recursive
iterative
static
anonymous
A function must be defined before it is _________
called
deleted
printed
assigned
The return statement is used to _________ a value from a function.
return/send back
delete/remove
print/display
store/save
In the loop below, the inner loop runs _________ times per outer iteration.
for i in range(3):
for j in range(2):
pass
2
3
1
0
When two conditions must be true, we use the _________ operator.
and
or
not
xor
if x > 0 or y > 0: print("Positive") This prints "Positive" if _________ condition is true.
any one
both
none
exactly one
Default parameter values are defined in a function using the ________ symbol.
=
+
*
&
The opposite of or is ________.
and
if
not
xor
def show(): print("Hello") Here, show is the ________ of the function.
name
body
parameter
return value
A function that does not return anything implicitly returns _________
None
0
False
Null
A nested loop can be used to process _________ data structures like matrices.
2D (two-dimensional)
linear
hierarchical
single-dimensional
A compound condition allows multiple comparisons in a _________ statement.
single
double
loop
In def sum(a, b):, a and b are called _________.
parameters
functions
statements
operators
In the call sum(3, 4), 3 and 4 are _________.
arguments
variables
functions
operators
A function can return multiple values using _________
tuple (comma-separated values)
list (square-bracketed values)
dictionary (key-value pairs)
set (curly-braced values)
Compound conditions are mainly used in _________ statements.
if / decision-making
looping
assignment
A nested loop with both loops running 5 times will execute the inner body _________ times.
25
10
5
15
