Need help with this problem
This first function translates normal words into "pirate speak"
def translate_pirate_word(word):
if word == "my":
return f"me"
elif word == "you":
return f"ye"
elif word == "is":
return f"be"
elif word == "are":
return f"be"
elif word == "hello":
return f"ahoy"
elif word == "yes":
return f"arr"
elif word == "friend":
return f"matey"
elif word == "friends":
return f"hearties"
else:
return f"{word}"
This function takes a sentence then translates "pirate words" into the ones applicable
def translate_to_pirate(normal_sentence):
normal_sentence += " "
empty =""
pirate_sentence = ""
for char in normal_sentence:
if char != " ":
empty = empty + char
else:
pirate_sentence += translate_pirate_word(empty)
empty =" "
return pirate_sentence
When I run this function to test it it prints out " matey are" so it translates the first word but not the following words.
I have tested it with other things too like translate_to_pirate("yes hello") and it does the same thing and only translates the first word
print(translate_to_pirate("friend are "))
Any help is welcome
Thanks :)