Python Forum
Displaying a long list with Rows and Columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying a long list with Rows and Columns
#3
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.

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 ':(
Reply


Messages In This Thread
RE: Displaying a long list with Rows and Columns - by ngr33n - Sep-21-2017, 04:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Displaying list correspond to the column number danlopek14q 9 4,228 Aug-27-2021, 04:32 AM
Last Post: naughtyCat
  sorted list not displaying Crackity 6 5,356 Jul-18-2017, 12:50 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020