0

Write a program to create a function to accept N number return how many prime number.

28th Oct 2016, 3:38 AM
Rakesh
Rakesh - avatar
3 Antworten
+ 1
def isPrime(number): numbers = range(2,number)  for i in numbers: if number % i == 0: return False   break  return True count = 0 user = int(input("give a number")) for i in range(2,user+1):   if isPrime(i): count += 1 print("The number of prime ",count)
28th Oct 2016, 12:36 PM
Iqbal Mohammad Rhidwan
Iqbal Mohammad Rhidwan - avatar
0
To optimize that i would divide by 2 the "number" in line 2. actually i have made one of these, check if You want
28th Oct 2016, 5:03 PM
Iago Muñoz Varela
Iago Muñoz Varela - avatar
0
Hmm. I saw your code and i really appreciate it.
28th Oct 2016, 5:07 PM
Iqbal Mohammad Rhidwan
Iqbal Mohammad Rhidwan - avatar