Please place your programs in seperate files named as described in the problem. Improperly named programs will not count. Turn in your files by placing them in the dropbox. Please be mindful of the late policy.
Create a program that turns nested lists into tree objects and vice-versa.
makeTree(nestedList)that takes lists of the form
[value, childList]and recursively creates a tree out of
TreeNodes which it then returns.
printTree(root, level)which prints out a tree recursively, with
*before each entry.
dumpToList(root)that takes a tree object and returns it converted into a list.
Hint: You can multiply a string by an integer to get multiple copies
of a string.
'*'*5 is the same as
You should be able to create a list in the specified format, convert it into a tree, convert that tree into a list, and then convert the list into a tree again. When printed, the trees should look the same.
Include the following test code in your file:
root = MakeTree([1,[[2,[[3,],[4,]]],[5,[[6,],[7,]]]]]) asList = DumpToList(root) PrintTree(root,0) PrintTree(MakeTree(asList),0)
It should print out the following:
1 * 2 ** 3 ** 4 * 5 ** 6 ** 7 1 * 2 ** 3 ** 4 * 5 ** 6 ** 7
Modify your program from 4.1:
TypeErrorfor when the user gives the wrong number of arguments.
ValueErrorfor when the user gives something that is not a number when it should be (i.e., something like 'cow' instead of 5)
loaddisk. Each one should expect the user to give the name of the file.
loaddiskshould have its own
IOErrorif the file does not exist.
? range 1- Bad value ? range 10 11 Wrong number of arguments ? range 10 Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ? savedisk ten Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ? quit Goodbye! ######### NEW RUN OF PROGRAM ######## ? loaddisk cow No such file: cow Result:  ? loaddisk ten Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]