Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a python recursive function return the same result (set) as picture. def b

ID: 3844044 • Letter: W

Question

write a python recursive function return the same result (set) as picture.

def bases(aclass):

We learned that when we declare a class using inheritance, the _bases_ attribute of the class is bound to a tuple of references to its base classes. Write a recursive function named bases that takes a reference to any class and returns a set containing that class and all its base classes (back to object). You may not use the _mro_ or _mro_ attributes of the class, which would trivialize your function. You may use both iteration (over the _bases_ list) and recursion. For example, given the following class definitions in a Script class F: pass class C: pass class G: pass class B(F): pass class D(G): pass class A(B, C, D): pass

Explanation / Answer

from timeit import Timer from fibo import fib t1 = Timer("fib(10)","from fibo import fib") for i in range(1,41): s = "fibm(" + str(i) + ")" t1 = Timer(s,"from fibo import fibm") time1 = t1.timeit(3) s = "fibi(" + str(i) + ")" t2 = Timer(s,"from fibo import fibi") time2 = t2.timeit(3) print("n=%2d, fib: %8.6f, fibi: %7.6f, percent: %10.2f" % (i, time1, time2, time1/time2))