I'm stuck on problem set 1. Trying to figure out the prime number generator. Any help?
Well, a prime is only divisible by 1 and itself, right? Also, other than 2, all primes are odd. So, divide things by an appropriate number of odd values and see if you end up with a solution without a remainder. If so, it is not prime.
what do you have so far?? if you need to post your code.. please use a code pasting site: - http://dpaste.com - http://pastebin.com - https://gist.github.com/ - http://pastie.org - http://codepad.org - http://ideone.com - http://www.repl.it/ paste your code there and post the link here. select Python syntax highlighting when u paste.
This is what someone on YT coded. I understand the concept, but not the nuts and bolts of it. Nevertheless, this code just prints prime numbers and not the specific 1000th prime as indicated in the problem set. I was really excited to do CS but as of late I'm getting really discouraged by my lack of ability to do even the simplest codes. How do you know if you're cut out for this? Thanks for the advice and help... def findPrime(n): for x in range (2,n): if (n % x == 0): return False else: return True for n in range (2, 50): if(findPrime(n)==True): print n
using pen(cil) and paper try to step thru the code by hand - the more you do this the better you will understand the nuts and bolts. the more practice you have at this, the easier it will be when you have to do it three years from now on a piece of code you are trying to figure out. I hesitate to give you the following link but it is too good a tool - you should learn to do this by hand (the muscle action helps it get in your brain). http://pythontutor.com/
You probably need to teach yourself a little about the Python language before you are more comfortable- you won't get that in the course. read the Tutorial in the Python documentation and play around with all the examples given. read How To Think Like A Computer scientist and play around with all the examples given - http://www.greenteapress.com/thinkpython/html/index.html this is also a good one - http://beastie.cs.ua.edu/cs150/book/index.html practice the examples given in all sources you find. play around with the examples, change them up a bit to see what happens. practicing writing in the examples will help you get more familiar with the language and the concepts.
Join our real-time social learning platform and learn together with your friends!