QUESTION IMAGE
Question
question: 10
what would this program print?
x_pos = 16
y_pos = 20
computes the midpoint between (0,0)
and the point
def compute_distance(x_pos, y_pos):
print(\original point: \ + str(x_pos) + \, \ + str(y_pos))
print(\midpoint from origin: \ + str(x_pos/2) + \, \ + str(y_pos/2))
compute_distance(12, 14)
print(\point: \ + str(x_pos) + \, \ + str(y_pos))
Step1: Analyze function call
The function compute_distance is called with arguments 12 and 14. Inside the function, x_pos and y_pos in the function scope refer to these arguments. So, the first print statement in the function prints Original Point: 12, 14.
Step2: Calculate mid - point
For the mid - point calculation, x_pos/2 = 12/2=6.0 and y_pos/2 = 14/2 = 7.0. So, the second print statement in the function prints Midpoint from Origin: 6.0, 7.0.
Step3: Analyze the last print statement
After the function call, the last print statement accesses the global variables x_pos = 16 and y_pos = 20 (since the function call with local variables 12 and 14 does not change the global x_pos and y_pos). So, it prints Point: 16, 20.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
Original Point: 12, 14
Midpoint from Origin: 6.0, 7.0
Point: 16, 20