-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTalkLikeAPirate.py
More file actions
38 lines (33 loc) · 999 Bytes
/
TalkLikeAPirate.py
File metadata and controls
38 lines (33 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Rex Reynolds
#Talk like a Pirate
#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
#Read the input and do the printing loop
#Takes the English to pirate dictionary as input.
def readInput(aDict):
from random import randrange
import re
print("Arr! Welcome to the Pirate translator!")
user = raw_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: ")
rand = randrange(10)
def main():
the_dict = createDictionary()
readInput(the_dict)
main()