anonymous
  • anonymous
Ok im back! im on ps3 and have completed part a ( http://dpaste.com/546011/ ) however,Im stuck on part b. I know this is incorrect but here's what i came up with: http://dpaste.com/546014/ help please....
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 :)
SOLVED
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.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
double-oh. i used a list instead of a tuple. this may be cheating but from my understanding, you can't add into a tuple -- they are immutable. so, any command within your loop asking the program to add an index value into a tuple doesn't work. or so i understand. if someone out there knows i am wrong about this, please correct me. here is a copy of my program for that part of problem set 3 if this helps you to see how idid this: http://dpaste.com/546072/
anonymous
  • anonymous
thanks, but the problem clearly states to return a tuple so I need a tuple
anonymous
  • anonymous
found out how to fix your problem. create the list then mutate it into a tuple and return the tuple value. thanks for the help

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

vaboro
  • vaboro
alicebaker77: you don't have a 'return' statement in your script, and so your function will return 'None', I suppose...
vaboro
  • vaboro
double_o_seven & alicebaker77: I suppose there is no other way but to convert a list to a tuple before the function returns...
vaboro
  • vaboro
I tried to implement recursion in solution ps3b.py as well: http://pastebin.com/MT80xS3h; however, I couldn't find how not to pass 'positions' and 'index' as parameters. In other words, in oder to implement recursion in ps3b.py I passed a list of positions of the key and starting search index as parameters of the function. Strange things happened when I tested my recursive functional implementation. I can assign default valued to parameters 'positions' and 'index': def subStringMatchExactRecursive(target, key, positions=[], index=0): Now, I can supposedly call the function without explicitly passing arguments for parameters 'positions' and 'index': subStringMatchExactRecursive(target, key) But if I do this twice in a row: subStringMatchExactRecursive(target, key) subStringMatchExactRecursive(target, key) I will have the correct result first time, but second time the correct result will be appended to the first correct result. If I call the recursive function three times, I will have the correct result the first time, second time I will have two appended correct results in a tuple and third time I will have three correct appended results in a tuple. This seems to be the way Python works. Can somebody explain to me what is really happening during function execution?
vaboro
  • vaboro
double_o_seven & alicebaker77: I found the way to "append" a tuple :-) a = (1,2) b = (3,4) c = a + b Now c = (1,2,3,4)
vaboro
  • vaboro
For ps3a and ps3b if key == "" what do you think the function should return: an empty string or an index of the target, i.e. a tuple like this: (0,1,2,3,4,...,n) where n is len(target)-1???

Looking for something else?

Not the answer you are looking for? Search for more explanations.