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.
‘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.
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.)
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).....
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.
First syntax error I got was the capital W in While, should be all lowercase.
‘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.
Try four spaces. (The pound sign creates headings.)