Computer Science

Predict the output of the following code:

def Changer(P, Q = 10):
    P = P / Q
    Q = P % Q
    return P

A = 200
B = 20
A = Changer(A, B)
print(A, B, sep = '$')
B = Changer(B)
print(A, B, sep = '$', end = '###')

Python

Python Functions

3 Likes

Answer

10.0$20
10.0$2.0###

Working

The code snippet provided defines a function Changer that takes two parameters P and Q, where Q is assigned a default value of 10. Inside the function, P is divided by Q and P is assigned the quotient, and then Q is assigned the remainder of P divided by Q. The modified P value is returned from the function. In the main code, variables A and B are initialized with values 200 and 20, respectively. The Changer function is called first with A and B as arguments, modifying the value of A. The updated values of A and B are then printed with a separator of '$'. Next, the Changer function is called again with only B as an argument, updating B. Finally, the updated values of A and B are printed again with a separator of '$' and an end marker of '###'.

Answered By

2 Likes


Related Questions