Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 6 - Functions - Section 6.9 - The Scope of Variables - Check Point - MyProgrammingLab - Page 188: 6.17

Answer

(a) The printout will be following- 2 3.4 2 4 (b) The printout will be following- 3 6 5

Work Step by Step

(a) When function is called it is given the argument 2 for parameter x, so in the first line of function it will print 2, then the next 2 lines will change the values of x and y but only in the scope of the function. Then the function will also print the modified value of y that is 3.4. Then after the function ends the value of x and y will not be updated and printed as it is, because the changes were only in the scope of the function. (b) In the first call the function is called with 1 as argument of all parameters x, y and z. It will return x+y+z that is 3, which will be printed. In the second call the values of x, y and z will be 2, 1, 3 and the return value will be 2 + 1 + 3 = 6. In the third call the value for y is not provided so it will take default value mentioned in function header and the return value will be 1+1+3 = 5.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.