Computer Science, asked by purveshKolhe, 2 days ago

Write a program in python to print top 100 prime numbers​

Answers

Answered by anindyaadhikari13
6

Solution:

Here comes the co‎de for the question.

def isPrime(n):

   if n==1:

       return False

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

       if n%i==0:

           return False

   return True

# main

print("Prime numbers from 1 to 100 are as follows:")

for i in range(1,100):

   if isPrime(i):

       print(i,end=" ")

Here, the isPrime() function checks whether the number is prime or not. Then a loop is created in the range(1,100). Inside the loop, the above mentioned function is called. It checks whether the value of the control variable is prime or not. If prime, number is displayed on the screen.

See the attachment for output.

•••♪

Attachments:
Answered by Anonymous
3

Answer:

Python Program to Print all Prime Numbers between an Interval

#Take the input from the user:

lower = int(input("Enter lower range: "))

upper = int(input("Enter upper range: "))

for num in range(lower,upper + 1):

if num > 1:

for i in range(2,num):

if (num % i) == 0:

break.

Explanation:

Similar questions