Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

Problem Set 2, #3

OpenStudy (anonymous):

OpenStudy (anonymous):

for some reason it isnt working, when launched it just remains a blank screen

OpenStudy (anonymous):

I just did it this morning. I'll take a look at it.

OpenStudy (anonymous):

The only I see wrong right off the back is you never assigned in in your test statement to fix that you can add 1 argument to your test function which would be n. I'm going to try it now and tell you if it works.

OpenStudy (anonymous):

You also didn't assign count in test(). I don't understand what you were trying to do with count in test I don't think those do anything

OpenStudy (anonymous):

ok wait let me upload my most recent one

OpenStudy (anonymous):

ok sorry some indentation issues...heres the most recent one, it just returns -5

OpenStudy (anonymous):

ok still in test you are not giving it an argument therefore n is not assigned inside the function test(). Your argument should be test(n).

OpenStudy (anonymous):

ok now it just returns -5 once...i guess thats an improvement

OpenStudy (anonymous):

In your test function the body of your else statement should be even with "for a in range(0,n)" because the way yours is setup it will only check the first possible solution in stead of all solutions in (0,n) and would you rather me explain everything or post a fixed code.

OpenStudy (anonymous):

can you please post a fixed code then if i have any questions ill ask you?

OpenStudy (anonymous):

Yea one sec lemme do it really quick.

OpenStudy (anonymous):

and i know some people use tuples or lists on this problem, thats not needed right?

OpenStudy (anonymous):

No it can be done either way http://dpaste.com/hold/529001/

OpenStudy (anonymous):

Do you want to see it done with a list?

OpenStudy (anonymous):

no thanks, i havent tried it yet so i'd rather attempt on my own but thanks for all the help!

OpenStudy (anonymous):

so basically i just had to get rid of the else statement because it was causing it to check for only one value?

OpenStudy (anonymous):

you had to add the argument to test which was test(n). I deleted the print n-5 in test there was no point to it. Your return n-5 should only be return n. I also deleted your n=0 its outside the function and isn't doing anything.

OpenStudy (anonymous):

sorry I forgot to comment out the wrong stuff instead of deleting it.

OpenStudy (anonymous):

its fine i understood it all, main thing was deleting the else statement...but why exactly do i need an arguement for test?

OpenStudy (anonymous):

try it without the arguments you get a name error because functions have local variables. so unless you tell it to take an argument none of the variables you are already using will carry over. Therefor the n in cheese() will not moved to test() unless you tell it to by putting test(n).

OpenStudy (anonymous):

Did that help?

OpenStudy (anonymous):

yeah thanks

OpenStudy (anonymous):

thanks btw im 16 so we are the young ones of this school lolz

OpenStudy (anonymous):

Yeah, no problem and thats cool haha I'll be 16 in June.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!