What is the purpose of a function in Python?
To perform a specific task or calculation
To store data
To create loops
To display output on the screen
Which keyword is used to define a function in Python?
Def
Function
Define
Fun
How do you call a function in Python?
By using the function name followed by parentheses
By using the 'call' keyword
By using the 'execute' keyword
By using the 'run' keyword
What is the purpose of a return statement in a function?
To specify the value that the function should output
To end the execution of the function
To print a message on the screen
To define the parameters of the function
Which of the following is NOT a valid way to define a function in Python?
Def my_function():
Function my_function():
Def my_function:
Def my_function(parameters):
What is the output of the following code?\ndef add_numbers(a, b):\n return a + b\n\nresult = add_numbers(3, 5)\nprint(result)
8
35
15
53
What is the purpose of the 'if' statement in Python?
To perform different actions based on conditions
To define a loop
To print output on the screen
To declare variables
Which symbol is used for equality comparison in Python?
==
=
!=
<>
What is the output of the following code?\n\nx = 5\ny = 10\n\nif x > y:\n print('x is greater than y')\nelse:\n print('x is not greater than y')
X is not greater than y
X is greater than y
X is equal to y
Error: x and y are not defined
What is the purpose of a loop in Python?
To repeat a block of code multiple times
To define conditions
To perform calculations
To store data
Which type of loop is used when the number of iterations is known in advance?
For loop
While loop
Do-while loop
Repeat-until loop
What is the output of the following code?\n\nfor I in range(5):\n print(i)
0\n1\n2\n3\n4
1\n2\n3\n4\n5
0\n1\n2\n3\n4\n5
Error: range() function requires an argument
Which type of loop is used when the number of iterations is not known in advance?
While loop
For loop
Do-while loop
Repeat-until loop
What is the output of the following code?\n\ni = 0\nwhile I < 5:\n print(i)\n I += 1
0\n1\n2\n3\n4
1\n2\n3\n4\n5
0\n1\n2\n3\n4\n5
Error: I is not defined
Which statement is used to exit a loop prematurely?
Break
Continue
Return
Exit
What is the syntax for defining a function in Python?
Def function_name():
Function_name():
Function_name:
Def function_name
Which keyword is used to pass a value back from a function in Python?
Return
Pass
Yield
Break
What is the purpose of parameters in a function?
To accept input values
To define the function name
To specify the return type
To control the flow of execution
Which of the following is NOT a valid way to call a function in Python?
Function_name()
Function_name
Call function_name
Function_name(parameters)
Function_name(parameters=values)
What is the output of the following code?\n\ndef multiply_numbers(a, b):\n return a * b\n\nresult = multiply_numbers(4, 5)\nprint(result)
20
9
45
25
What is the purpose of an if-else statement in Python?
To make decisions based on conditions
To repeat a block of code
To define a function
To handle exceptions
Which symbol is used for greater than or equal to comparison in Python?
>=
<=
==
!=
What is the output of the following code?\n\nx = 10\ny = 5\n\nif x != y:\n print('x is not equal to y')\nelse:\n print('x is equal to y')
X is not equal to y
X is equal to y
10 is not equal to 5
10 is equal to 5
What is the purpose of a loop in Python?
To repeat a block of code
To make decisions based on conditions
To define a function
To handle exceptions
Which type of loop is used when the number of iterations is known in advance?
For loop
While loop
Do-while loop
If-else loop
What is the output of the following code?\n\nfor I in range(3):\n print(i)
0\n1\n2
1\n2\n3
0\n1\n3
1\n2\n4
Which type of loop is used when the number of iterations is not known in advance?
While loop
For loop
Do-while loop
If-else loop
What is the output of the following code?\n\ni = 0\nwhile I < 3:\n print(i)\n I += 1
0\n1\n2
1\n2\n3
0\n1\n3
1\n2\n4
Which statement is used to exit a loop prematurely?
Break
Continue
Pass
Return
What is the purpose of the 'continue' statement in Python?
To skip the rest of the current iteration
To exit the loop prematurely
To repeat a block of code
To handle exceptions
{"name":"What is the purpose of a function in Python?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"What is the purpose of a function in Python?, Which keyword is used to define a function in Python?, How do you call a function in Python?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker