Ultimate access to all questions.
What will be the output of the function check_input
when executed with input parameters 1 and 3? The function is defined as follows:
def check_input(x, y):
if x < y:
x = x + 1
if x > y:
x = x + 1
if x < y:
x = x + 1
return x
Explanation:
The output of the function check_input(1, 3)
will be 3. Here's why:
x = 1
and y = 3
.if
Statement: Since 1 < 3
is true, x
is incremented to 2
.if
Statement: 2 > 3
is false, so x
remains 2
.if
Statement: 2 < 3
is true, leading x
to be incremented to 3
.x
, which is 3
.Thus, the correct answer is 3.