wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

G1Q1

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

__________ is the built-in function to know the type of a variable or function.

a)

id()

b)

type()

c)

data_type()

d)

None of the above

2.

__________ keyword is used for creating a function in Python.

a)

define

b)

 fun

c)

 def

d)

function

3.

What is the best solution to repeated code? Select the correct answer.


a)

All options are wrong.

b)

Wrapping the code into one function.

c)

Leave the code as is.

d)

Split code into multiple functions.

4.

Consider the following Python function:

def dbl_plus(x):

    return 2*x + 1

 What is the purpose of the function dbl_plus(x)?


a)

Doubles the input and subtracts 1

b)

Multiplies the input by 2

c)

 Doubles the input and adds 1

d)

Adds 1 to the input

5.

Given the code snippet:

val = -5

if val < 0:

    result = -val

else:

    result = val

print(result) 

 What will be printed as the output?


a)

5

b)

-5

c)

0

d)

10

6.

In the code snippet for i in [30, 40, 50]: print(i), what is being printed? 


a)

 Fahrenheit to Celsius conversion for each value

b)

Values along with their square roots

c)

Values along with their increments

d)

Values as they are in the list

7.

Based on the provided code for the variable height: Suppose the variable height is given the value of 75. What will be printed?

if height > 100:

    print("space")

elif height > 50:

    print("mesosphere")

elif height > 20:

    print("stratosphere")

else:

    print("troposphere")


a)

mesosphere

b)

space

c)

stratosphere

d)

troposphere

8.

What is the primary purpose of a list in Python?

a)

A list is used for mathematical calculations.


b)

A list is a container that can hold a fixed number of items of different types.


c)

A list is used for sorting data efficiently.


d)

 A list is used for creating dictionaries.


9.

 How is a list created in Python?

a)

Using curly braces: {1, 2, 3}

b)

Using parentheses: (1, 2, 3)

c)

Using angle brackets: <1, 2, 3>

d)

Using square brackets: [1, 2, 3]

10.

What is the output of the following code snippet?

L = ['I did it all', 4, 'love']

for i in range(len(L)):

    print(L[i])


a)

I did it all 4 love

b)

I did it all, 4, love

c)

I, did, it, all, 4, love

d)

Error

11.

 How can you insert an element at the end of a list? 

a)

list.append(x)

b)

list.insert(i, x)

c)

list.extend(L)

d)

list.add(x)

12.

What does the `list.remove(x)` method do?


a)

Removes the first item from the list whose value is x

b)

Removes the last item from the list whose value is x

c)

Removes all occurrences of x from the list

d)

Removes the item at index x from the list

13.

def square(x):

    return x*x

 What does the `square` function do?


a)

Computes the sum of two numbers.


b)

Multiplies a number by itself.


c)

Calculates the square root of a number.

d)

Rounds a floating-point number.


14.

In the loop `for i in [3, 4, 5]:

print("Start body")

print(i)

print(i*i)`, what is the output of the first iteration?

a)

Start body \n 3 \n 9


b)

Start body \n 3 \n 6


c)

3 \n 9


d)

Start body \n 3

15.

In Python, what is the purpose of the continue statement in a loop?

a)

 It terminates the loop prematurely.


b)

 It restarts the loop from the beginning.


c)

 It skips the rest of the code in the loop and moves to the next iteration.


d)

It checks if the loop condition is met.


16.

What is the output of the following Python code?

def outer_function(x):

    def inner_function(y):

        return x + y

    return inner_function

closure_example = outer_function(10)

print(closure_example(5))

a)

50

b)

5

c)

15

d)

10

17.

Consider the following Python loop:

for i in range(2, 8, 2):

    print(i*i)

What will be the output of this loop?

a)

4, 8, 16, 64

b)

4, 16, 64

c)

4, 8, 16, 36

d)

 4, 16, 36

18.

Consider the following loop:

numbers = [2, 4, 6, 8, 10]

total = sum(x*x for x in numbers if x > 5)

What is the value of the total variable after the loop execution?

a)

200

b)

164

c)

120

d)

156

19.

Consider the following function:

def exponential_sum(base, n):

    result = 0

    for i in range(n):

        result += base**i

    return result

What does the exponential_sum(2, 4) return?

a)

30

b)

31

c)

14

d)

15

20.

Consider the following function:

def findExtremeDivisors(num1, num2):

    result = []

    for i in range(2, min(num1, num2) + 1,80):

        if num1 % i == 0 and num2 % i == 0:

            result.append(i)

    return result

What does the function findExtremeDivisors(100, 200) return? 

a)

 [[2], [100]]

b)

[2]

c)

 [80]

d)

 [100, 200]