The following def is my assignment .. the problem is the accumulator pattern gets me very lost. I don't know how to write it.. I have asked my instructor for help and he refers me to the sad sad book we have been given.
I DO NOT WANT THIS QUESTION ANSWERED.
This def takes a string and returns pirate talk.
Example: toPirate('hello')
.. should return a different word from the dictionary..
'avast'
Otherwise:
it should just return the previous word that is not in the dictionary.
Example:
toPirate('hello dad') 'avast dad'
I am just lost on this and would like a similar example of a def .. so I can do my own work on this and thus not get in trouble .. thanks!
(Also sorry if my words confuse .. I don't know all the 'right words' for things yet.
#################################################################################
Also this DEF is not yet complete .. the instructor got me this far.
#################################################################################
def toPirate(string):
dictionary={'hello':'avast','excuse':'arrr','sir':'matey','boy':'matey',
'man':'matey','madam':'proud beauty','officer':'foul blaggart',
'the':"th'",'my':'me','your':'yer','is':'be','are':'be',
'restroom':'head','restaurant':'galley','hotel':'fleabag inn'}
#initiate accumulator
acc=[]
#update accumulator
words=string.split()
for x in words:
if x in dictionary:
acc=acc+[dictionary[x]]
#return accumulator
#################################################################################
Hopefully someone is nice enough to teach me what others just can't :(