-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpig_latin_practice.py
57 lines (36 loc) · 1.21 KB
/
pig_latin_practice.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Convert input text into Pig Latin
###################################################
# Student should add code where relevant to the following.
import simplegui
# Pig Latin helper function
def is_consonant(first_letter):
vowels = ['a','e','i','o','u']
if not(first_letter in vowels):
return True
def pig_latin(word):
"""Returns the (simplified) Pig Latin version of the word."""
first_letter = word[0]
rest_of_word = word[1 : ]
# Student should complete function on the next lines.
if is_consonant(first_letter):
return rest_of_word + first_letter + "ay"
else:
return word + "way"
# Handler for input field
def get_input(word):
print pig_latin(word)
# Create frame and assign callbacks to event handlers
frame = simplegui.create_frame("Pig Latin translator", 200, 200)
frame.add_input('Translate', get_input, 100)
# Start the frame animation
frame.start()
###################################################
# Test
get_input("pig")
get_input("owl")
get_input("tree")
###################################################
# Expected output from test
#igpay
#owlway
#reetay