Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

here's my cut on ps1a: #using for loops primeNums=[2,] print('Computing Primes using for loops') for x in range(3,10000,2): for y in range(2,x): z=x%y if z == 0: break else: primeNums+=[x,] if len(primeNums)>=1000: break print('the Thousandth Prime Number is: ',x)

OpenStudy (anonymous):

added an input function to the while loop code ## using while loop ########Declarations primeNums=[2,] x=3 print('Computing Primes using while loop') b=int(input('Which prime Number would you seek today?')) print('Computing Prime') while len(primeNums)<=b-1: #len(primeNums)<=999 #determines how high to 'find' primeNums for y in range (2,x): #returns number for prime divisor test z=x%y #tests for prime if z==0: #breaks from loop if not prime x+=1 #increments to next number break else: primeNums+=[x,] x+=1 # if num is prime, adds to list, and moves to next #print(primeNums[A]) #test to view all nums cantenated. print('Prime Number',b,'is: ',x-1) #prints requested prime num

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!