http://codepad.org/fZHWhfpc this is what I would turn in as PS1 problem 1. Now on to problem 2. C&C please
Looks good! Only critique is that your primality test counts 0 and 1 as prime: see http://codepad.org/Ttw7jBKx Doesn't really matter for the problem but something to consider.
I guess you could in force that "n" can't equal 0 or 1--or must strictly start at 2 (since its the first prime), but definitely a good first start. How would you enforce "n" being 2 or != 0 or 1?
before your "for x in range (2, int(math.sqrt(n)) + 1):" statement, you could include: if n < 2: return False
Then 2 and three wouldn't show up on the list. I would say that this program as it is would get 100%--unless the professors like to nitpick
Join our real-time social learning platform and learn together with your friends!