answersLogoWhite

0

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

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

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


Why wont this python program print work?

This is the program that I couldn't fit in the question: Sorry for the underscores but it wouldn't let me indent# !/usr/bin/python# Filename: prime5.py#y = int(input('How many prime numbers do you want to see?'))x = 6w = 0primes = [2,3,5]z = len(primes)j = 0while w != 1:____if y*0!=0:________y = input('Please pick another NUMBER: ')____elif y*0==0:________w = w + 1while z


What is the Sum of first n natural numbers?

int sum = 0; int i; for(i = 0; i &lt; n; ++i) { sum += i; }


Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&amp;n); printf("\n"); for(i=2;i&lt;=n;i++) { for(j=2;j&lt;=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }


Python function that lists prime numbers?

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

Related Questions

How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


What are the first three prime numbers?

The first three prime numbers are 2,3 and 5.


What are the first twenty six prime numbers?

The first 26 prime numbers are :- 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97and 101


What is the sum of the first 250 prime numbers?

The sum of the first 250 prime numbers is 182,109.


What will be the sum of the first 25 prime numbers?

The sum of the first 25 prime numbers is 1,060.


What is the sum of the first 15 prime numbers?

the sum of the first 15 prime numbers is 328 .


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


What is the arithmetic mean of the sum of the first five prime numbers and the sum of the cubes of the first three prime numbers?

The sum of the first five prime numbers is 28. The sum of the cubes of the first three prime numbers is 160. The average of 28 and 160 is 94.


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


Are there more even prime numbers or odd prime numbers?

All prime numbers are odd, exept of the first prime number 2.