NEW
Font size
WorksheetsG1Q1
Total questions: 20
Worksheet time: 13mins
__________ is the built-in function to know the type of a variable or function.
id()
type()
data_type()
None of the above
__________ keyword is used for creating a function in Python.
define
fun
def
function
What is the best solution to repeated code? Select the correct answer.
All options are wrong.
Wrapping the code into one function.
Leave the code as is.
Split code into multiple functions.
Consider the following Python function:
def dbl_plus(x):
return 2*x + 1
What is the purpose of the function dbl_plus(x)?
Doubles the input and subtracts 1
Multiplies the input by 2
Doubles the input and adds 1
Adds 1 to the input
Given the code snippet:
val = -5
if val < 0:
result = -val
else:
result = val
print(result)
What will be printed as the output?
5
-5
0
10
In the code snippet for i in [30, 40, 50]: print(i), what is being printed?
Fahrenheit to Celsius conversion for each value
Values along with their square roots
Values along with their increments
Values as they are in the list
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")
mesosphere
space
stratosphere
troposphere
What is the primary purpose of a list in Python?
A list is used for mathematical calculations.
A list is a container that can hold a fixed number of items of different types.
A list is used for sorting data efficiently.
A list is used for creating dictionaries.
How is a list created in Python?
Using curly braces: {1, 2, 3}
Using parentheses: (1, 2, 3)
Using angle brackets: <1, 2, 3>
Using square brackets: [1, 2, 3]
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])
I did it all 4 love
I did it all, 4, love
I, did, it, all, 4, love
Error
How can you insert an element at the end of a list?
list.append(x)
list.insert(i, x)
list.extend(L)
list.add(x)
What does the `list.remove(x)` method do?
Removes the first item from the list whose value is x
Removes the last item from the list whose value is x
Removes all occurrences of x from the list
Removes the item at index x from the list
def square(x):
return x*x
What does the `square` function do?
Computes the sum of two numbers.
Multiplies a number by itself.
Calculates the square root of a number.
Rounds a floating-point number.
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?
Start body \n 3 \n 9
Start body \n 3 \n 6
3 \n 9
Start body \n 3
In Python, what is the purpose of the continue statement in a loop?
It terminates the loop prematurely.
It restarts the loop from the beginning.
It skips the rest of the code in the loop and moves to the next iteration.
It checks if the loop condition is met.
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))
50
5
15
10
Consider the following Python loop:
for i in range(2, 8, 2):
print(i*i)
What will be the output of this loop?
4, 8, 16, 64
4, 16, 64
4, 8, 16, 36
4, 16, 36
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?
200
164
120
156
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?
30
31
14
15
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?
[[2], [100]]
[2]
[80]
[100, 200]
