course# 6.00 Assignment# 1 Hi guys, do any of you have an idea for what I can use instead of zip in this piece of code http://dpaste.com/778395/ ??
your code es hard to reading. in my opinion this code is more readeble una funcion me facilita trabajar con codigo muy extenso. se puede reutilizar y a mi parecer de eso se trata todo el punto 1 http://dpaste.com/778396/
I am quite lost, what is the purpose of the script?
That is a really good idea, now I just have the problem that it hits an infinite loop at append.primes(n) where it appends n an infinite amount of times until it hits 1000 in primes_found... Can you see why it does that? Because I don't get why. http://dpaste.com/781781/
That actually seems to be exactly what I wanted :D But just for the sake of me understanding it better I hope you don't mid me asking: 1: What does the and p == primes += 1 part do for the process exactly? and 2: why did my code not work? And what I mean by that is, that by my logic it should be working and looping properly (witch was clearly not the case for the looping part) so I think I wasn't communicating properly to the interpreter what I wanted it to do, but I don't really see why it did not loop as I wanted. It can then be discussed that your version was more effective putting check_int += 1 in the start of the loop instead of in all the conditionals and stuff like that, but my question is still about the looping. Thanks a lot :D
i didn't actually try your code - the first thing i saw is that the loop at line nine uses check_int_list but check_int_list never gets updated - you would be usinf the same number over and over. then, it looks like the loops at lines 8 and 9 are reversed - you want to test your number against all the primes in the list - for each number you want to check you want to run thru the list of primes. it helps to write down in words a sort of pseudocode explaining what you are trying to do - then turn it into code - it is easier than just trying to write the code off the top of your head. print statements are a good way to debug your code - it lets you see what is actually happening so you can compare to what you intended - here is your code with print statements - http://dpaste.com/782220/ I added p == primes[-1] because you cannot say a number is prime till you have tested it with all the previous primes. [-1] is a slice that points to the last item in a list - i think the tutorial in the Python docs covers slices. += is an operator that adds the number on the right to the number on the left. a+=1 is equivalent to a = a+1. This operator is listed in the Python documentation which should be installed on your computer (F1 from within Idle).
Join our real-time social learning platform and learn together with your friends!