I am trying to store the output of the below code into a list
lower = int(input("Enter the begining of the range: "))
upper = int(input("Enter the end of the range: "))
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
numlist = []
numlist.append(num)
print(numlist)
I am expecting the output to be inside a list [p1, p2, p3,...pn]
. However, I end up with the following:
Enter the begining of the range: 1
Enter the end of the range: 10
Prime numbers between 1 and 10 are:
[2]
[3]
[5]
[7]
Is this approach correct or are there better ways to meet the requirement? I am also trying to add a line of code that will let the user that there (4) numbers that are prime between 1 and 10.