Description:
"Find all the prime numbers between 1 and 4,027 and print them in a table which
"reads down", using as few rows as possible, and using as few sheets of paper
as possible. All numbers should be right-justified in their column. The height
of the columns should all be the same, except for perhaps the last column,
which might have a few blank entries towards its bottom row. After printing
the table, re-print in a second table of twin primes found among the original
prime numbers, again reading down.
Finally, print the following statistics: number of primes found and the number
of twin prime pairs found. Recall, all tables require titles."
I got the program to calculate all of the prime numbers in the range, but don't know how to display it. The numbers need to be printed in order, not from left to right, but from top to bottom, if that makes sense. I'm just printing to the console and the copy and pasting it to a Microsoft Word Document.
Like this:
"Find all the prime numbers between 1 and 4,027 and print them in a table which
"reads down", using as few rows as possible, and using as few sheets of paper
as possible. All numbers should be right-justified in their column. The height
of the columns should all be the same, except for perhaps the last column,
which might have a few blank entries towards its bottom row. After printing
the table, re-print in a second table of twin primes found among the original
prime numbers, again reading down.
Finally, print the following statistics: number of primes found and the number
of twin prime pairs found. Recall, all tables require titles."
I got the program to calculate all of the prime numbers in the range, but don't know how to display it. The numbers need to be printed in order, not from left to right, but from top to bottom, if that makes sense. I'm just printing to the console and the copy and pasting it to a Microsoft Word Document.
Like this:
1 7 19 37 2 11 23 41 3 13 29 43 5 17 31 47Not like this:
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47I know I need a nested for loop, but have never done anything like this. This is my Attempt:
def findPrimes(n): """ Adds the calculated prime numbers to an empty list. """ prime_list = [2] for number in range(3, n, 2): if all(number % i != 0 for i in range(2, int(number ** .5) + 1)): prime_list.append(number) return prime_list def displayPrimes(): for row in findPrimes(4027): for col in findPrimes(4027): display = row * col print(display, end = "\t") break # main program findPrimes(4027) displayPrimes() # output statistics print("\n\nThe number of prime numbers in the range is: " + str(len(findPrimes(4027))))