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)

20th Jun 2020, 7:55 AM
Lalit kumar
Lalit kumar - avatar
1 Odpowiedź
+ 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)
20th Jun 2020, 8:38 AM
Avinesh
Avinesh - avatar