Can somebody post a solution to Problem Set 1 A? I've spent 3 hours on it and can't get it. I keep getting bugs everywhere. I know that the simplest way to do it is just have a counter that when below 1000, x value increases by 1, y value that goes from 2 to x, and if x%y!=0, then counter goes up by 1. When counter=1000 print x. I have no idea how to actually code this. I can figure out things that aren't divisible by specific integers, but when I try to test for divisibility by all numbers in a list y (which is necessary for testing for prime number), Python just doesn't let me.
Have you reat the Tutorial in the Python docs? Have you read the readings associated with the lecture? write down in words what you are trying to do and then try to turn that into code don't worry about bugs - they are a fact of life print statements are an effective troubleshooting tool post what you have so far - please use a code pasting site: - http://dpaste.com - http://pastebin.com - http://www.repl.it/ - http://pastie.org - http://codepad.org - http://ideone.com paste your code there and post the link here. select Python syntax highlighting when u paste.
Are you sure your on problem set 1 A? I just finished it and your explanation sounds like a different problem maybe?
@Tomboy couple of different versions of this class that ppl take - 2008 and 2011 and it is given at EDx but i have seen too many posters from there this go around
bwCA's advice to write down the steps that you need to do to accomplish your task is spot on. I've been using notes like that as comments for the different sections of my programs, and then writing my code to do what the comment says. This also creates modular code. I'm only writing a few lines ( less than 15 ) of code at a time before I test it, which is called unit testing, so the bugs are easier to find. Like bwCA said, print statements can be invaluable for troubleshooting.
Join our real-time social learning platform and learn together with your friends!