fork download
  1. def pow_printer(max_val, max_pow):
  2. # What we are doing is creating sublists, so that for each sublist, we can
  3. # print them separately
  4. _ret = [[pow(v, p) for p in range(1, max_pow+1)] for v in range(1, max_val+1)]
  5. # The above produces, with max_val = 5 and max_pow = 5:
  6. # [[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]]
  7.  
  8. # Now, we are looping through the sub-lists in the _ret list
  9. for l in _ret:
  10. for var in l:
  11. # This is for formatting. We as saying that all variables will be printed
  12. # in a 6 space area, and the variables themselves will be aligned
  13. # to the right (>)
  14. print "{0:>{1}}".format(var,
  15. len(str(max_val**max_pow))), # We put a comma here, to prevent the addition of a
  16. # new line
  17. print # Added here to add a new line after every sublist
  18.  
  19. # Actual execution
  20. pow_printer(8, 7)
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
      1       1       1       1       1       1       1
      2       4       8      16      32      64     128
      3       9      27      81     243     729    2187
      4      16      64     256    1024    4096   16384
      5      25     125     625    3125   15625   78125
      6      36     216    1296    7776   46656  279936
      7      49     343    2401   16807  117649  823543
      8      64     512    4096   32768  262144 2097152