Advertisement
Ilikebugs

R.L Numbers

Nov 20th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. def isItPrime(N):# same as before
  2.   x=""
  3.   if x<2:
  4.     return("Not Prime")
  5.   elif x==2:
  6.     return("Prime")
  7.   else:
  8.     for D in range(2, N):
  9.       if (D * D > N):          # first added line
  10.         break                  # second added line
  11.       if N % D == 0:
  12.         x="Not Prime"
  13.         return("Not Prime")
  14.     if x!="Not Prime":
  15.       return("Prime")
  16.  
  17. print(isItPrime(3))
  18. print(isItPrime(4))
  19. def lastThreePrimes(n):
  20.     x=2
  21.     m = []
  22.     while x<=n:
  23.       if isItPrime(x) == "Prime":
  24.         m.append(str(x))
  25.       x+=1
  26.     return int(m[-3])+int(m[-2])+int(m[-1])
  27. n=5
  28. while n<101:
  29.   y = lastThreePrimes(n)
  30.   z = n
  31.   print ("%s has a value of %s" % (z,y))
  32.   n+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement