This question was suggested to me by a friend. It goes something like this:- Given two integers i and n, starting from i print the next n prime numbers
Note:- The question is asking for the next n prime numbers not and has not specified a range such as i to n.
This is what I came up with, but unfortunately, it's not working. Can you help?
def is_prime(Num):
prime = True
if Num > 1:
for i in range(2, Num):
if (Num % i) == 0:
prime = False
if prime:
return Num
if __name__ == "__main__":
startNum = int(input("Enter the first number: "))
primeNum = int(input("Enter the number of primes you want to print: "))
primeList = []
length = len(primeList)
while length <= primeNum:
x = is_prime(startNum)
primeList.append(x)
startNum = startNum + 1
length = length + 1
print(primeList)
print(x)
The output is as follow
Enter the first number: 3
Enter the number of primes you want to print: 5
[3, None, 5, None, 7, None]
None