I have a question regarding problem set 2 (problems 3 and 4). The code I wrote for question 3 (codepad.org/0kL2qT3X) gives me the correct answer. However, when I try to adapt the code (codepad.org/VCopk3Ib) in order to solve question 4, I get a 'Timeout'. Can anyone tell me why? Thanks
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
sometimes it helps to put print statements in your code to see what is going on.
looks like you are on the right track - you might take a look at the limits in your range functions
Thanks for your help. Using multiple break statements did the trick. Is there any way to break out of nested loops more elegantly?
break is the only way i know of to break out of a loop
After each for statement i 'broke out' if the the equation evaluated to greater than n.
i thought that if you limited the range of your for loops you might not run into the timeouts. you weren't getting timeouts on your computer were you?