#Prime Calculator #Inspired by Eric Steadman's comparable Scratch program and written by Isaac Wheeler in Python #get operator input, then calculate the next [input] primes #see if I can figure out how to not have error with non-integer input print('How many primes?') run = int(input()) currentPrime = 5 allPrimes = [2, 3] #final list while run > 0: primeTest = True #variable which is used to confirm primeness for p in allPrimes: #if it doesn't work, change testPrimes back to allPrimes if currentPrime % p ==0: primeTest = False if primeTest: allPrimes.append(currentPrime) run = run - 1 currentPrime = currentPrime + 1 for p in allPrimes: p = str(p) print(allPrimes) #check the run-- for loop with a range instead of while loop? #it wasn't subtracting run with every prime- did it with every number it tested #Eric has his only do the modulus of the primes less than or equal to the square root of the number-- #if I do that, will it end up increasing the speed? #not by much-- but it's there, nonetheless
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