QMB3302 Midterm Guide
True or false: all operators produce an int output - answer false
What is the output of the following code:
x=2
y=3
x=3
z=4
print(x+y) - answer6
What is a function in python? - answerA block of code that performs a specific task and
can be reused.
What is the purpose of a for loop in python? - answerto iterate over a sequence, such
as a list or string
What does a break statement do in a loop? - answerIt immediately exits the loop,
skipping any remaining iterations
What is the difference between elif and else? - answerelif checks additional conditions,
else handles the default case.
What is a default argument in a python function? - answerAn argument that takes a
default value if no value if provided during the function call.
What is the correct way to sum values in a list using a for loop? - answerInitialize a total
variable before the loop and add each value to it inside the loop.
How would you count the number of iterations in a for loop? - answerInitialize a counter
variable outside the loop and increment it inside the loop.
How do you pass arguments to a function in Python? - answerBy specifying the
arguments inside the parentheses when calling the function.
What is the main advantage of using functions in python? - answerThey allow code to
be reused and organized into manageable sections.
What does *args do in a python function? - answerit allows the function to accept an
arbitrary number of positional arguments.
What is a nested if statement? - answeran if statement placed inside another if
statement.
True or false: all operators produce an int output - answer false
What is the output of the following code:
x=2
y=3
x=3
z=4
print(x+y) - answer6
What is a function in python? - answerA block of code that performs a specific task and
can be reused.
What is the purpose of a for loop in python? - answerto iterate over a sequence, such
as a list or string
What does a break statement do in a loop? - answerIt immediately exits the loop,
skipping any remaining iterations
What is the difference between elif and else? - answerelif checks additional conditions,
else handles the default case.
What is a default argument in a python function? - answerAn argument that takes a
default value if no value if provided during the function call.
What is the correct way to sum values in a list using a for loop? - answerInitialize a total
variable before the loop and add each value to it inside the loop.
How would you count the number of iterations in a for loop? - answerInitialize a counter
variable outside the loop and increment it inside the loop.
How do you pass arguments to a function in Python? - answerBy specifying the
arguments inside the parentheses when calling the function.
What is the main advantage of using functions in python? - answerThey allow code to
be reused and organized into manageable sections.
What does *args do in a python function? - answerit allows the function to accept an
arbitrary number of positional arguments.
What is a nested if statement? - answeran if statement placed inside another if
statement.