Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
## A program to print prime numbers in an interval of 0 to the number entered by the user.

## Primes are integers greater than one with no positive divisors besides 1 and itself. Negative numbers are excluded.

upperBound = int(input("Please enter the upper bound of range:"))

for number in range(1,upperBound + 1):  # testing all numbers in range 1 to upperBound
   if number > 1:                       # prime numbers are greater than 1, the smallest prime number is 2.
       for i in range(2,number):        # testing all numbers in range 2 to (number - 1)
           if (number % i) == 0:        # if the number has any factor other than itself, then break out of the inner for loop
               break
           else:                        # if the number doesn't have any factor other than itself, print it as a prime.
               print(number)
               break