From 01963feeaa57c73156a0e5b3f2d0874ed1dea14a Mon Sep 17 00:00:00 2001 From: Aarni Honka <4585172+shopro@users.noreply.github.com> Date: Thu, 1 Oct 2020 06:27:57 +0300 Subject: [PATCH] Added translations and modified to work with Python 3 --- TalkLikeAPirate.py | 20 +++++++++----------- Translation.txt | 10 ++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 Translation.txt diff --git a/TalkLikeAPirate.py b/TalkLikeAPirate.py index fa32ecf..1659471 100644 --- a/TalkLikeAPirate.py +++ b/TalkLikeAPirate.py @@ -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 @@ -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() diff --git a/Translation.txt b/Translation.txt new file mode 100644 index 0000000..f886747 --- /dev/null +++ b/Translation.txt @@ -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 \ No newline at end of file