0
Can u please explain why this code is giving this output:250#150, 250#100, 130#100
def change(P,Q=30): P=P+Q Q=P-Q print (P,'#',Q) return (P) R=150 S=100 R= change(R,S) print (R,'#',S) S= change(S)
1 Antwort
+ 5
def change(P,Q=30): // P=150 and Q=100, and Q will only be 30 when you do not pass a 2nd parameter.
P=P+Q // P=150+100=250
Q=P-Q // Q=250-100=150
print (P,'#',Q) // 250 # 150
return (P) // return 250
START HERE
--------------------
R=150
S=100
R= change(R,S) // function is called with 150,100 passed to it. Move to function.
R now holds 250 since it is returned from the function.
print (R,'#',S) // 250 # 100
Do the same for the function call below.
S= change(S)