wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz3-CC102-MakScie

Total questions: 40

Worksheet time: 40mins

Name
Class
Date
1.

for i in range(2):

    for j in range(3):

        print(i, j)

How many times will the inner loop execute?

a)

A) 2

b)

B) 3

c)

C) 5

d)

D) 6

2.

for i in range(1, 4):

    for j in range(1, i + 1):

        print("*", end="")

    print()

What is the last line printed?

a)

***

b)

**

c)

*

d)

Blank line

3.

What will be printed?

count = 0

for i in range(2):

    for j in range(2):

        count += 1

print(count)

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) 1

4.

In nested loops, which loop runs the most?

a)

A) Outer

b)

B) Inner

c)

C) Both equally

d)

D) Depends on code

5.

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)

A) 4

b)

B) 5

c)

C) 6

d)

D) 2

6.

x = 10

if x > 5 and x < 15:

    print("In range")

Output?

a)

Error

b)

No output

c)

In range

d)

Out of range

7.

and and or are examples of:

a)

Loop keywords

b)

Compound condition operators

c)

Arithmetic operators

d)

Iterators

8.

x, y = 5, 10 if x < y or y < 0: print("Valid")

a)

Valid

b)

Invalid

c)

Nothing

d)

Error

9.

x, y = 5, 10

if x < y or y < 0:

    print("Valid")

Output:

a)

True

b)

False

c)

Error

d)

None

10.

Which function definition is correct?

a)

function add(x, y):

b)

def add(x, y)

c)

def add(x, y):

d)

add(x, y): def

11.

def add(a, b=2):

    return a + b

 

print(add(3))

Output?

a)

A) 2

b)

B) 3

c)

C) 5

d)

D) Error

12.

def f(x):

    return x * 2

 

print(f(f(2)))

Output?

a)

2

b)

4

c)

8

d)

Error

13.

def test(a, b):

    if a > b and a > 0:

        return True

    return False

print(test(5, 3))

Output:

a)

True

b)

False

c)

Error

d)

None

14.

for i in range(1, 4):

    for j in range(1, 3):

        if i == j:

            break

        print(i, j)

Total printed pairs?

a)

A) 2

b)

B) 3

c)

C) 4

d)

D) 5

15.

for i in range(1, 4):

    for j in range(1, 4):

        if i == j:

            continue

        print(i, j)

How many total prints?

a)

6

b)

7

c)

8

d)

9

16.

Which keyword is used to define a function in Python?

a)

define

b)

func

c)

def

d)

function

17.

def multiply(x, y):

    return x * y

 

print(multiply(2, 3) + multiply(3, 2))

Output?

a)

12

b)

10

c)

9

d)

8

18.

What is the output?

def display(n):

    while n > 0:

        print(n, end=" ")

        n -= 1

display(3)

a)

3 2 1

b)

1 2 3

c)

Error

d)

Infinite loop

19.

for i in range(1, 4):

    for j in range(1, 4):

        if (i + j) % 2 == 0:

            print(i, j)

How many pairs printed?

a)

4

b)

5

c)

6

d)

3

20.

def func(a, b):

    return a if a > b else b

print(func(3, 5))

Output?

a)

3

b)

5

c)

True

d)

False

21.

A loop inside another loop is called a _________

a)

nested loop

b)

infinite loop

c)

conditional loop

d)

single loop

22.

Compound conditions combine two or more conditions using _________ or _________.

a)

and, or

b)

if, else

c)

true, false

d)

add, subtract

23.

for i in range(2): for j in range(2): print("Hi") This prints “Hi” _________ times.

a)

4

b)

2

c)

6

d)

8

24.

A function that calls itself is known as a _________ function.

a)

recursive

b)

iterative

c)

static

d)

anonymous

25.

A function must be defined before it is _________

a)

called

b)

deleted

c)

printed

d)

assigned

26.

The return statement is used to _________ a value from a function.

a)

return/send back

b)

delete/remove

c)

print/display

d)

store/save

27.

In the loop below, the inner loop runs _________ times per outer iteration.
for i in range(3):
   for j in range(2):
      pass

a)

2

b)

3

c)

1

d)

0

28.

When two conditions must be true, we use the _________ operator.

a)

and

b)

or

c)

not

d)

xor

29.

if x > 0 or y > 0: print("Positive") This prints "Positive" if _________ condition is true.

a)

any one

b)

both

c)

none

d)

exactly one

30.

Default parameter values are defined in a function using the ________ symbol.

a)

=

b)

+

c)

*

d)

&

31.

The opposite of or is ________.

a)

and

b)

if

c)

not

d)

xor

32.

def show(): print("Hello") Here, show is the ________ of the function.

a)

name

b)

body

c)

parameter

d)

return value

33.

A function that does not return anything implicitly returns _________

a)

None

b)

0

c)

False

d)

Null

34.

A nested loop can be used to process _________ data structures like matrices.

a)

2D (two-dimensional)

b)

linear

c)

hierarchical

d)

single-dimensional

35.

A compound condition allows multiple comparisons in a _________ statement.

a)

single

b)

double

c)

loop

d)

print

36.

In def sum(a, b):, a and b are called _________.

a)

parameters

b)

functions

c)

statements

d)

operators

37.

In the call sum(3, 4), 3 and 4 are _________.

a)

arguments

b)

variables

c)

functions

d)

operators

38.

A function can return multiple values using _________

a)

tuple (comma-separated values)

b)

list (square-bracketed values)

c)

dictionary (key-value pairs)

d)

set (curly-braced values)

39.

Compound conditions are mainly used in _________ statements.

a)

if / decision-making

b)

looping

c)

assignment

d)

print

40.

A nested loop with both loops running 5 times will execute the inner body _________ times.

a)

25

b)

10

c)

5

d)

15