Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isItPrime(N):# same as before
- x=""
- if x<2:
- return("Not Prime")
- elif x==2:
- return("Prime")
- else:
- for D in range(2, N):
- if (D * D > N): # first added line
- break # second added line
- if N % D == 0:
- x="Not Prime"
- return("Not Prime")
- if x!="Not Prime":
- return("Prime")
- print(isItPrime(3))
- print(isItPrime(4))
- def lastThreePrimes(n):
- x=2
- m = []
- while x<=n:
- if isItPrime(x) == "Prime":
- m.append(str(x))
- x+=1
- return int(m[-3])+int(m[-2])+int(m[-1])
- n=5
- while n<101:
- y = lastThreePrimes(n)
- z = n
- print ("%s has a value of %s" % (z,y))
- n+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement