Here is my code for Problem Set 1. Any ways to condense code? Part 1: http://dpaste.com/725513/ Part 2: http://dpaste.com/725516/ Both work fine. Ask away if you are stuck.
congrats here is mine, i stored all the primes in a list and kept looking till there were 1000 items in the list - http://dpaste.com/725633/
Wow, your script is so nice and concise, and it works too:o. Too bad I don't really understand what you did b/c i don't know much of the more complex syntax. Good job though, hopefully after i'm done this course I can go back and understand what you did haha.
bwCA: nice solution. Attached is my version. I short circuited 2 and 3. Hope this helps.
kevinw198: regarding my second solution I used log where you used log (,10). Our answers defer and I don't know which one is the correct. Maybe someone can throw in his/her answers into the mixture. My solution seems to agree with the ratio becoming 1 as the primes become larger. Hope this helps.
kevinw198: If I remove the log(,10) and replace it with log -- I think this is natural log and change the lines (there are two) ratio=n/sum to ratio=x/sum we match.
I don't know why I used based 10 instead of natural log. I assumed natural log was "ln" function, and in high school, log base 10 was usually just written as log for me. But I think the code is correct though. I looked at your solution, but I didn't really understand what the break function does.
The break function serves to exit from within a loop and continue from the first line after. Imagine you have a for loop from 1 to 1000. In order "jump out" you use break. Hope this helps.
http://docs.python.org/reference/simple_stmts.html#the-break-statement http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#testing-for-truth-values The only thing i did different was store the primes in a list. http://docs.python.org/tutorial/introduction.html#lists http://docs.python.org/tutorial/datastructures.html#more-on-lists
Join our real-time social learning platform and learn together with your friends!