answersLogoWhite

0


Best Answer

If you just want a hint:

One way to check whether a number is prime is by dividing it by any number between 2 and the square root of your number. If the number divides by any of these, it is not prime.

If you want the code:

import math for num in range(1,101): if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)): print num

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Python function that lists prime numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a program in Python to find the first n prime numbers?

One way to do this is to write a function that checks if a number is prime: def isPrime(number): for i in range(2, number): if number%i == 0: return False return True Then create variables to track how many primes have been found and a variable to track which number is being tested for being prime. Increment that variable and test it, and if it is prime print it out (or save it somewhere) and increment the variable being used to track how many primes have been found: targetPrimes = 10 #number of primes to find primesFound = 0 #number of primes found i = 1 while (primesFound < targetPrimes): i += 1 #first number tested is 2 if isPrime(i): print(i) primesFound += 1


Is 38 a composite number?

Yes. All non-prime numbers are composite numbers, which simply means a number has one or more prime factors other than 1 and the number itself.


How boolean function works?

A boolean function is simply a function that returns a boolean value - a value that can either be "true" or "false". The return value may be used to see whether a function was successful, for example:if openfile("somefile.txt")// The file was opened succesfully, we can now proceedA boolean function will often reply to a question which can be replied with "yes" or "no". For example, you can have a function that asks the user to confirm an action:if user_confirms("Are you sure you want to delete this file?")// Delete the file hereOr:if isPrime(myNumber)// Output: "Your number is a prime number"else// Output: "Your number is not a prime number"A boolean function is simply a function that returns a boolean value - a value that can either be "true" or "false". The return value may be used to see whether a function was successful, for example:if openfile("somefile.txt")// The file was opened succesfully, we can now proceedA boolean function will often reply to a question which can be replied with "yes" or "no". For example, you can have a function that asks the user to confirm an action:if user_confirms("Are you sure you want to delete this file?")// Delete the file hereOr:if isPrime(myNumber)// Output: "Your number is a prime number"else// Output: "Your number is not a prime number"A boolean function is simply a function that returns a boolean value - a value that can either be "true" or "false". The return value may be used to see whether a function was successful, for example:if openfile("somefile.txt")// The file was opened succesfully, we can now proceedA boolean function will often reply to a question which can be replied with "yes" or "no". For example, you can have a function that asks the user to confirm an action:if user_confirms("Are you sure you want to delete this file?")// Delete the file hereOr:if isPrime(myNumber)// Output: "Your number is a prime number"else// Output: "Your number is not a prime number"A boolean function is simply a function that returns a boolean value - a value that can either be "true" or "false". The return value may be used to see whether a function was successful, for example:if openfile("somefile.txt")// The file was opened succesfully, we can now proceedA boolean function will often reply to a question which can be replied with "yes" or "no". For example, you can have a function that asks the user to confirm an action:if user_confirms("Are you sure you want to delete this file?")// Delete the file hereOr:if isPrime(myNumber)// Output: "Your number is a prime number"else// Output: "Your number is not a prime number"


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


What is the set builder notation for prime numbers?

Set builder notation for prime numbers would use a qualifying condition as follows. The set of all x's and y's that exist in Integers greater than 1, such that x/y is equal to x or 1.

Related questions

Is there a List of prime numbers between 100 and 200?

Yes. Just search Google for "list of prime numbers", and you'll get not only that, but much larger lists as well. You might also look at the Wikipedia article on "prime numbers"; this will give you links to lists of prime numbers.


How can you use the prime factorizations of two numbers to determine if they realatively prime?

List the prime factorisations side by side in ascending order. If any prime factor is on both lists they are not relatively prime. If the two lists are disjoint, the numbers are relatively prime.


What are the square and prime numbers?

Those are infinite lists.


What are all of the prime numbers and composite numbers?

Both of those lists are infinitely long.


How do you tell prime numbers without finding the factors?

There are lists of them online.


How many prime numbers are there between 600 and 700?

You can find lists of prime numbers online in many places. Just search Google for "list of prime numbers" or something similar.


What is the sum of all the prime numbers between 55 and 90 and between 200 and 215?

By searching Google for "list of prime numbers" you can get several lists, for example here: http://primes.utm.edu/lists/small/1000.txt


What are the prime numbers from 0-2000?

http://primes.utm.edu/lists/small/1000.txt


How many prime numbers are there from 1-100explain?

You can find a list of prime numbers here:http://primes.utm.edu/lists/small/1000.txtNote that this is just the start of an infinite sequence, but for the question asked, it is enough.You can find a list of prime numbers here:http://primes.utm.edu/lists/small/1000.txtNote that this is just the start of an infinite sequence, but for the question asked, it is enough.You can find a list of prime numbers here:http://primes.utm.edu/lists/small/1000.txtNote that this is just the start of an infinite sequence, but for the question asked, it is enough.You can find a list of prime numbers here:http://primes.utm.edu/lists/small/1000.txtNote that this is just the start of an infinite sequence, but for the question asked, it is enough.


What is the function of prime numbers?

They are the building blocks or all the numbers. Composite numbers are made of primes.


Is 97 a prime?

yes. here is a list of the first 1,000 prime numbers. http://primes.utm.edu/lists/small/1000.txt


What are all of the twin prime numbers?

There are an infinite number of pairs of prime two apart, classified as "twin primes". For lists, see the link.