def pow_printer(max_val, max_pow):
# What we are doing is creating sublists, so that for each sublist, we can
# print them separately
_ret = [[pow(v, p) for p in range(1, max_pow+1)] for v in range(1, max_val+1)]
# The above produces, with max_val = 5 and max_pow = 5:
# [[1, 1, 1, 1, 1], [2, 4, 8, 16, 32], [3, 9, 27, 81, 243], [4, 16, 64, 256, 1024], [5, 25, 125, 625, 3125]]
# Now, we are looping through the sub-lists in the _ret list
for l in _ret:
for var in l:
# This is for formatting. We as saying that all variables will be printed
# in a 6 space area, and the variables themselves will be aligned
# to the right (>)
print "{0:>{1}}".format(var,
len(str(max_val**max_pow))), # We put a comma here, to prevent the addition of a
# new line
print # Added here to add a new line after every sublist
# Actual execution
pow_printer(8, 7)
ZGVmIHBvd19wcmludGVyKG1heF92YWwsIG1heF9wb3cpOgogICAgIyBXaGF0IHdlIGFyZSBkb2luZyBpcyBjcmVhdGluZyBzdWJsaXN0cywgc28gdGhhdCBmb3IgZWFjaCBzdWJsaXN0LCB3ZSBjYW4KICAgICMgcHJpbnQgdGhlbSBzZXBhcmF0ZWx5CiAgICBfcmV0ID0gW1twb3codiwgcCkgZm9yIHAgaW4gcmFuZ2UoMSwgbWF4X3BvdysxKV0gZm9yIHYgaW4gcmFuZ2UoMSwgbWF4X3ZhbCsxKV0KICAgICMgVGhlIGFib3ZlIHByb2R1Y2VzLCB3aXRoIG1heF92YWwgPSA1IGFuZCBtYXhfcG93ID0gNToKICAgICMgW1sxLCAxLCAxLCAxLCAxXSwgWzIsIDQsIDgsIDE2LCAzMl0sIFszLCA5LCAyNywgODEsIDI0M10sIFs0LCAxNiwgNjQsIDI1NiwgMTAyNF0sIFs1LCAyNSwgMTI1LCA2MjUsIDMxMjVdXQoKICAgICMgTm93LCB3ZSBhcmUgbG9vcGluZyB0aHJvdWdoIHRoZSBzdWItbGlzdHMgaW4gdGhlIF9yZXQgbGlzdAogICAgZm9yIGwgaW4gX3JldDoKICAgICAgICBmb3IgdmFyIGluIGw6CiAgICAgICAgICAgICMgVGh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