0

I'm writing a program to find prime numbers. The program runs as expected. However, the requirement is to format the output so it looks like this:

enter image description here

My codes look like this and I have no idea what I should do to make the output looks like the one in the sample program..

def prime_numbers(n):
    prime_numbers = []
    n += 1
    numbers = ['P' for i in range(0, n + 1)]
    numbers[0] = 'N'
    numbers[1] = 'N'
    starting_index = 2
    while starting_index < n:
        while not numbers[starting_index] == 'P':
            starting_index += 1
        prime_numbers.append(starting_index)
        num = 2
        while (starting_index * num) < n:
            numbers[starting_index * num] = 'N'
            num += 1
        starting_index += 1
    print('All prime numbers from 0 to', n - 1)
    print(prime_numbers)

num = int(input('Enter a number range: '))
prime_numbers(num)
jamesy
  • 1
  • 1
  • Does the spacing matter? If not, you could just return prime_numbers in the function (instead of printing) and then use the solution here. `https://stackoverflow.com/questions/25991666/how-to-efficiently-output-n-items-per-line-from-numpy-array` – that_data_guy Nov 21 '22 at 04:13

0 Answers0