Tessellate S.T.E.M.S - Computer Science - School - Set 2 - Problem 5

Consider the following codes:

A -

1
2
3
4
5
6
myfunction(n):
   print("helloworld")
   ‎if n != 0:
   ‎  myfunction(n-1)
   ‎else:
   ‎  pass

B -

1
2
3
4
5
6
myfunction(n):
   ‎if n != 0:
   ‎  myfunction(n-1)
   ‎else:
   ‎  pass
   ‎print("helloworld")

We define the following terms:

Functional equivalence: If the functions terminate, they print the same values.

Differentiable: There exists an input on which the output of one function is different from the other.

Which of these apply to A and B?


This problem is a part of Tessellate S.T.E.M.S.

Functionally equivalent and not differentiable Neither functionally equivalent nor differentiable Not functionally equivalent, differentiable A and B are functionally equivalent and differentiable

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

If n >= 0 then both functions terminate and give the same result (print n+1 times "helloworld", functional equivalence), if n<0 then both functions do not terminate, but only A will print an infinite number of "helloworld", B prints nothing (differentiable).

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...