Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions TalkLikeAPirate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#create the dicitonary from English to Pirate
def createDictionary():
pirate_dict = {}
infile = open("Translation.txt",'r')
for line in infile:
line = line.strip()
linelist = line.split(":")
pirate_dict[linelist[0]] = linelist[1]
return pirate_dict
with open("Translation.txt",'r') as file:
for line in file:
line = line.strip()
linelist = line.split(":")
pirate_dict[linelist[0]] = linelist[1]
return pirate_dict


#Read the input and do the printing loop
Expand All @@ -19,17 +19,15 @@ def readInput(aDict):
from random import randrange
import re
print("Arr! Welcome to the Pirate translator!")
user = raw_input("Enter a line: ")
user = input("Enter a line: ")
whitelist = ['this']
splitUser = user.split()
rand = randrange(10)
while user != "quit":
for word in aDict:
user = re.sub(r"\b"+word+r"\b", aDict[word],user)
if rand <4:
user = user + " , arr."
print(user)
user = raw_input("Enter a line: ")
print("Translation:", user)
user = input("Enter a line: ")
rand = randrange(10)
def main():
the_dict = createDictionary()
Expand Down
10 changes: 10 additions & 0 deletions Translation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
hello:ahoy
sir:matey
hi:arrrr
friend:m'hearty
treasure:booty
take:billage
idiot:scallywag
vote:mutiny
talk:parley
captain:cap'n