You're looking at Less Wrong's discussion board. This includes all posts, including those that haven't been promoted to the front page yet. For more information, see About Less Wrong.

Prismattic comments on What are you working on? July 2013 - Less Wrong Discussion

8 Post author: David_Gerard 02 July 2013 04:39PM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (100)

You are viewing a single comment's thread.

Comment author: Prismattic 07 July 2013 05:17:55AM *  0 points [-]

I've decided to teach myself python, following MIT's online intro CS course. I'm on lesson 2, and so far, I've mainly reinforced my pre-existing impression that I'm not a particularly intuitive coder (my day job has nothing to with programming; it just seemed like it couldn't hurt to develop another skill).

I realize I'm probably misusing the thread asking this, but if someone can explain the first syntax error in the following snippet, I'd be most appreciative. I assume it has something to do with the way I'm nesting the conditionals, but I've played around with it quite a bit without success (If there's more than one syntax error, just correct the first one, since that's what has me stuck. I'd rather try to puzzle out further glitches on my own first).....

divisor = 3
lastprime = 3
primecount = 2
While primecount < 1000:
lastprime = lastprime + 2
while divisor < lastprime:
if lastprime % factor != 0:
divisor = divisor + 2
else: lastprime = lastprime + 2 and divisor = 3
primecount = primecount + 1
print ("The thousandth prime number is")
print (lastprime)

As an aside -- there is apparently no relationship between aptitude for learning natural languages (I speak four with varying degrees of fluency) and learning synthetic languages, as the above mess presumably shows.

Comment author: JayDee 07 July 2013 12:30:07PM 1 point [-]

First syntax error I got was the capital W in While, should be all lowercase.

Comment author: Kawoomba 07 July 2013 02:59:06PM 0 points [-]

'factor' is not defined, you probably meant 'divisor'.

Not a syntax error, but the variable name 'lastprime' is named wrongly.

As per your request no further explicit help, but write the code with some binary isPrime dummy function, then once you're sure the logic is correct expand the isPrime with the actual prime check. It helps disconfuddling some of the potential confuddlers.

Think about the logic top down, high level first.

Comment author: wedrifid 07 July 2013 05:46:21AM 0 points [-]

ETA: clearly my lack of aptitude extends to how to properly display this in a comment here, as simply commenting out the code with the pound sign obviously isn't working as intended.

Try four spaces. (The pound sign creates headings.)