How to print prime numbers from 1 to n

0 votes

How to print prime number from 1 to n?

Oct 13, 2020 in Python by divyashree
• 120 points

recategorized Oct 13, 2020 by Niroj 2,314 views

1 answer to this question.

0 votes

Hello @divyashree

def isPrime(n):

    # Corner case

    if n <= 1 :

        return False

    # check from 2 to n-1

    for i in range(2, n):

        if n % i == 0:

            return False

    return True

  

# Function to print primes

def printPrime(n):

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

        if isPrime(i):

            print(i, end = " ")

  

# Driver code

if __name__ == "__main__" :

    n = 7

    # function calling

    printPrime(n)

Hope it helps!!

Thank you!!

      

answered Oct 13, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer

Sum of prime numbers from m to n in python

def is_prime(number):     if number < 2:         return False     for i ...READ MORE

answered Jan 5 in Python by Ali
812 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,220 points

edited Aug 8, 2018 by Omkar 8,137 views
0 votes
1 answer

How to read numbers from file in Python?

Assuming you don't have extraneous whitespace: with open('file') ...READ MORE

answered Apr 16, 2019 in Python by SDeb
• 13,300 points
7,488 views
0 votes
0 answers

How to print square of first 100 natural numbers using iterations in python?

Can you make a program with nested ...READ MORE

Jul 22, 2019 in Python by Waseem
• 4,540 points
995 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
0 votes
1 answer

What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

Hii @kartik, As always with Android there's lots ...READ MORE

answered May 26, 2020 in Java by Niroj
• 82,840 points
3,628 views
+1 vote
12 answers
0 votes
1 answer

How to pretty-print a numpy.array without scientific notation and with given precision?

Hii @kartik, The numpy arrays have the method round(precision) which ...READ MORE

answered Apr 14, 2020 in Python by Niroj
• 82,840 points
3,077 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP