Using the BitShow recursive function from Recursion.py, call BitShow recursively over the range 1 to 256.
import sys import unittest diagnostic = True class Data: def __init__(self,data): self.value = data def __str__(self): return str(self.value) class Node: def __init__(self,data,prevNode=None): self.data = Data(data) self.prevNode = prevNode class Stack: def __init__(self): self.head = None def isEmpty(self): return self.head == None def top(self): try: return self.head.data except: return None def push(self, data): if self.head is None: self.head = Node(data) else: new_node = Node(data) new_node.prevNode = self.head self.head = new_node if diagnostic : print("\tpush: top - ",str(data)) def pop(self): if self.head is None: return None else: popped = self.head.data self.head = self.head.prevNode if self.head is not None: if diagnostic : print("\tpop - ",str(popped),"\ttop - ",self.head.data) else: if diagnostic : print("\tpop - ",str(popped),"\ttop - Empty") return popped def empty(self): return self.head == None class StackFrame(Stack): def __init__(self): Stack.__init__(self) def push(self,t): if diagnostic : print("Push Stackframe: "+str(t)) Stack.push(self,t) def pop(self): if diagnostic : print("Pop Stackframe: "+str(Stack.top(self))) return Stack.pop(self) def top(self): return Stack.top(self) def empty(self): return Stack.empty(self) frames = StackFrame() def bitshow(number): global frames if number > 0: frames.push(number) bitshow(number // 2) frames.pop() if number % 2: print('1') else: print('0') def forward(c): global frames if c != ord('['): # '[' is letter after 'Z' frames.push(chr(c)) print("forward: printing "+chr(c)) forward(c+1) frames.pop() def backwards(c): global frames if c != ord('['): # '[' is letter after 'Z' frames.push(chr(c)) backwards(c+1) print("backward: printing "+chr(c)) frames.pop() def printlist(alist,index): global frames if index < len(alist):="" print(alist[index])="" frames.push(alist[index])="" printlist(alist,index+1)="" frames.pop()="" def="" teststack():="" if="" diagnostic="" :="" print("stack="" diagnosis")="" sf="StackFrame()" sf.push(1)="" sf.push(2)="" sf.push(3)="" while="" sf.empty()="=" false:="" print(="" sf.pop()="" )="" return="" true="" def="" testbitshow(n):="" print("bitshow")="" bitshow(n)="" def="" testforwards(c):="" print("forwards")="" forward(c)="" def="" testbackwards(c):="" print("backwards")="" backwards(c)="" def="" testprintlist():="" print("printlist")="" lst="[42,68,35,1,70,25,79,59,63,65]" print(lst)="" printlist(lst,0)="" def="" dotests():="" global="" diagnostic="" diagnostic="True" print("-------------------")="" testforwards(65)="" #="" 65='A' print("-------------------")="" testbackwards(65)="" #="" 65='A' print("-------------------")="" testbitshow(10)="" #="" 10="" in="" binary="" is="" 1010="" print()="" print("-------------------")="" testprintlist()="" snumber="" def="" radix(number,base):="" global="" frames="" global="" snumber="" global="" diagnostic="" diagnostic="False" if="" number=""> 0: frames.push(number) radix(number // base,base) frames.pop() snumber += str(number % base) if diagnostic : print(number % base) return snumber def doBases(number): global snumber print("Original base 10 number ",number) for i in range(2,11): print("base ",i,"\t",radix(number,i)) snumber = '' class Tests(unittest.TestCase): global diagnostic diagnostic = True def test(self): self.assertEqual(testStack(),True) if __name__=='__main__': # unittest.main() doTests() doBases(170)