Sep-21-2017, 04:51 AM
I'm actually trying to make a table way bigger than 4x4. I was just using that as an example to show that I want the list to print in order down the column(top to bottom, not across the row(left to right). I'm really confused on how to print in order vertically and this is all I could come up with.
I'm sorry, but I'm confused on what you were trying to say above. I guess I'm dumb ':(
def findPrimes(n): """ Adds the calculated prime numbers to a list. """ prime_list = [1, 2] for number in range(3, n + 1, 2): if all(number % i != 0 for i in range(2, int(number ** .5) + 1)): prime_list.append(number) return prime_list def makeTable(n, col = 15): """ Displays the prime_list through rows and columns. """ prime_list = findPrimes(n) table_str = "" for index, item in enumerate(prime_list): table_str += ("%6d" % item) + "\t" if(index + 1) % col == 0: table_str += "\n" return table_str # main program findPrimes(4027) makeTable(4027) print(makeTable(4027)) # output statistics print("\nThe number of prime numbers in the range is: " + str(len(findPrimes(4027))))It lines up perfectly, but prints the list in order "left to right", and I'm trying to print it in order "vertically" a certain amount of rows before it moves all the way up to the next column, if you get me.
I'm sorry, but I'm confused on what you were trying to say above. I guess I'm dumb ':(