just getting started, doing the first problem set, it works, but hoping someone could critique it for me? (1000 prime)
One tip that will help you get responses is to post your code at codepad.org, then post the link here. Most people are wary about just downloading someone's code without looking at it first. Other than that, I did take a look at your code. The indentation shows up weird on my computer. It may just be that I use Notepad++ to do all my editing, so take that with a grain of salt. One thing you could do to make your code more readable is to give your variables names that mean things, ie. instead of x call it divisor, that way people know what you're doing with it without having to dig through the code.
First off, congrats on getting some working code. I would second iyeager's suggestion to use descriptive variables (though I used n and x in my prime test as well). I would also challenge you to modify your code so that it tests for primes until b = 1000. Though your code works and gets you the right answer (woohoo!), it would give you more flexibility if you replaced the outer for loop. For example, your current test could not find the 1,001 prime number, because n cannot be larger than 7919. Of course if you already know what the 1,001 prime number is (or you google it), you can just change the range in the outer for loop. But pretend you do not have that luxury. In short, you could modify your code such that until 1000 (or whatever number you want) primes are found, n will be incremented by 1 and its primality will be tested. Just as in your current code, each time a prime is found b will be increased by 1. If you do not want to do such extensive modification, I understand, and like I said, it already works, so good job.
Join our real-time social learning platform and learn together with your friends!