0

Only thing I could think of is something having to do with the else statement

    import csv

# Python program to display all the prime numbers within an interval

lower = 1
upper = 1000000000

print("Prime numbers between", lower, "and", upper, "are:")

f = open('PrimeNumberTest.csv', 'w')
writer = csv.writer(f)

for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(1, num):
           if (num % i) == 0:
               continue
       else:
           writer.writerow([int(i)])

CSV Format: It looks somewhat normal here but in the file itself, you can see that the numbers skip a line everytime

10

11

12

13

14

15

16
George Adams
  • 331
  • 4
  • 15
  • 1
    Free additional advice: Your `continue` should be a `break`, and you should write `num` not `i` to file – xjcl Nov 15 '20 at 20:47

1 Answers1

1

Yo should open the file with newline parameter:

open('PrimeNumberTest.csv', 'w', newline='')
Miguel Prz
  • 13,718
  • 29
  • 42