Computer Science, asked by shrutiverma383, 1 year ago

Write a python code which prints first 20 prime numbers using loop

Answers

Answered by MichMich0945
1

Answer:

It's not copied from the net I have typed it own

Code:

----------------------------------------------------------------------

  1. # Python program to display all the prime numbers within an interval
  2. # change the values of lower and upper for a different result
  3. lower = 0
  4. upper = 20
  5. # uncomment the following lines to take input from the user
  6. #lower = int(input("Enter lower range: "))
  7. #upper = int(input("Enter upper range: "))
  8. print("all numbers between",lower,"and",upper,"are:")
  9. for num in range(lower,upper + 1):
  10.   # prime numbers are greater than 1
  11.   if num > 1:
  12.       for i in range(2,num):
  13.           if (num % i) == 0:
  14.               break
  15.       else:
  16.           print(num)

--------------------------------------------------------------------------------------------------------------

Output:

----------------------------------------------------------------------

all numbers between 0 and 20 are:

2

3

5

7

11

13

17

19

hope this helps you........................Ω

Answered by sushiladevi4418
0

Answer:

Python code to print the first 20 prime numbers using loops.

Explanation:

Program:-

for Number in range (1, 73):

count = 0

for i in range(2, (Number//2 + 1)):

if(Number % i == 0):

count = count + 1

break

if (count == 0 and Number != 1):

print(" %d" %Number, end = ' ')

Output:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71

Similar questions