P46 Q Python program def main num 0 show meum def show me ar

P46) Q Python program def main num 0 show me(um) def show me arg): if arg 10: show me(arg 1) else: print (arg)main() What is the output of the above code and explain in detail.

Solution

If argument passed to the function is less than equal to 10

then it will print 11 as it will call the function show_me(arg+1) recursively and keep calling until passed arg is greater than 10.

Example:

pass arg=1

i.e  show_me(arg)= show_me(1)  

steps:show_me(2)

show_me(3)

show_me(4)

show_me(5)

show_me(6)

show_me(7)

show_me(8)

show_me(9)

show_me(10)

show_me(11)

now it will enter into the else part and execute print(arg) i.e print(11)

hence 11 will be printed.

Second case)if passed value i.e arg is greater than 10,then it will simply print that value i.e arg

example:arg=12 show_me(12) will execute the else part and will print the 12.

 P46) Q Python program def main num 0 show me(um) def show me arg): if arg 10: show me(arg 1) else: print (arg)main() What is the output of the above code and e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site