Ps1 Q1
Hi guys, Im stuck on Ps1 Q1 and would like some assistance with my code if possible. I've wrote the following into python:
x=3
a=2
primecount = 1
while primecount<1000:
while a
(*Spoil) Here are some suggestions: What you basically want to do is make a loop within a loop, like you've already done: the 'inner' loop finds the primes and the 'outer' loop counts the number of primes. When your loop is finished (primecount=1000), you want the command print(x) to be the next and last command, therefore you have to place this outside the loop. The interpreter gives you the value of x, which you have last assigned, which actually will be x=x+1 if you place this after the prime counter-command. So try placing this before so you will the correct x-value and not x=x+1 :)
if you haven't solved this already, you may want to take a look at your code where you increment x x = x+1 #this starts checking the next number #a <- should be reset right after however the a counter remains the same, so you 'skip' checking some numbers on the next number. you may also consider consolidating the prime count into the first if/else statement. you know you found a prime at one of the if or the else
Join our real-time social learning platform and learn together with your friends!