Find and write the output of the following python code:
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)
Answers
Answered by
73
Output:
250 # 150
250 # 100
130 # 100
Explanation:
Python code:
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)
Attachments:
Answered by
76
Following are the output for the above code:
Explanation:
Output:
- 250 # 150 250 # 100 130 # 100
Missing information :
- There is an indentation missing. So the statement "P=P+Q" to the statement "return (p)" is that part of the change function and except this statement, all are the outside of the change function.
Output Explanation:
- The first line initializes the value 150 to the R variable.
- Then the second line initializes the value 100 to the S variable.
- Then the change function is called and the P variable will take the value of R (150), the Q variable will take the value of s(100).
- Then the first statement of change function assigns the 250(150+100)(P+Q) value to the P variable.
- Then the second statement of the change function assigns the 150 (250-100) (P-Q) value to the Q variable.
- And this is the output as the first output which is like 250 # 150.
- Then the return statement returns the p variable value which is 250.
- Then this value holds the variable R with the outside of the function.
- Then the R and the s variable value is the output with the help of # tag which is the second output. And it is 250 # 100.
- Then again change function is called with the 100 value for S and Q will be 30 which is the default value.
- Then the change function will give output as 130 # 100 as the third output after executing the "P=P+Q" and "Q=P-Q" statements.
Learn more :
- Output : https://brainly.in/question/10336898
Similar questions
Geography,
6 months ago
English,
6 months ago
English,
6 months ago
Computer Science,
1 year ago
English,
1 year ago