A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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....
anonymous
 5 years ago
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....

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0doubleoh. 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
 5 years ago
Best ResponseYou've already chosen the best response.0thanks, but the problem clearly states to return a tuple so I need a tuple

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0found out how to fix your problem. create the list then mutate it into a tuple and return the tuple value. thanks for the help

vaboro
 5 years ago
Best ResponseYou've already chosen the best response.0alicebaker77: you don't have a 'return' statement in your script, and so your function will return 'None', I suppose...

vaboro
 5 years ago
Best ResponseYou've already chosen the best response.0double_o_seven & alicebaker77: I suppose there is no other way but to convert a list to a tuple before the function returns...

vaboro
 5 years ago
Best ResponseYou've already chosen the best response.0I 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
 5 years ago
Best ResponseYou've already chosen the best response.0double_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
 5 years ago
Best ResponseYou've already chosen the best response.0For 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???
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.