Write a python code which prints first 20 prime numbers using loop
Answers
Answered by
1
Answer:
It's not copied from the net I have typed it own
Code:
----------------------------------------------------------------------
- # Python program to display all the prime numbers within an interval
- # change the values of lower and upper for a different result
- lower = 0
- upper = 20
- # uncomment the following lines to take input from the user
- #lower = int(input("Enter lower range: "))
- #upper = int(input("Enter upper range: "))
- print("all numbers between",lower,"and",upper,"are:")
- for num in range(lower,upper + 1):
- # prime numbers are greater than 1
- if num > 1:
- for i in range(2,num):
- if (num % i) == 0:
- break
- else:
- print(num)
--------------------------------------------------------------------------------------------------------------
Output:
----------------------------------------------------------------------
all numbers between 0 and 20 are:
2
3
5
7
11
13
17
19
hope this helps you........................Ω
Answered by
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