Write a program that prompts the user for an integer and thenprints out all prime numbers up to that integer. For example,when the user enters 20, the program should print out:
2
3
5
7
11
13
17
19
Note: A prime number is not divisible by any number except 1and itself.

Respuesta :

Answer:

n=int(input("Enter number upto which you want to print prime numbers:\n"))#taking input of n in integer type..

for i in range(1,n): #looping over 1 to n.

   pr=True  #taking pr to be True..

   for div in range(2,i): #looping over 2 to i..

       if i%div==0:#if i is divisible by div then it is not prime

           pr=False#making pr false

   if pr and i!=1: #condition for printing

       print(str(i))#printing the prime numbers..

       

Explanation:

In the python program we have checked for every integer up to n that is is not divisible by any integer between 2 to n-1 both inclusive if it is then it is not a prime number.