import math class myMath(): #Python decided to do methods in a way that makes the instance #to which the method belongs be passed automatically, #but not received automatically: the first parameter of #methods is the instance the method is called on. #That makes methods entirely the same as functions, #and leaves the actual name to use up to you def findPrimes(self, lim): primes = [2,3] current = primes[-1] while(current < lim): factorFound = False for p in primes: #could stop at sqrt(bound) if current % prime == 0: factorFound = True break if not factorFound: knownPrimes.append(current) current += 2 p = FindPrimes() #FindPrimes p.findPrimes(100) sum = 0 print(PRIMES[-1]) #applications: #largest prime that can be represented by 3 bits, 12 bits, etc
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question