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
sometimes it helps to put print statements in your code to see what is going on. http://codepad.org/h2ig9GJy 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?
Join our real-time social learning platform and learn together with your friends!