-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathState.py
More file actions
55 lines (40 loc) · 1.42 KB
/
Copy pathState.py
File metadata and controls
55 lines (40 loc) · 1.42 KB
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
#!/usr/bin/env python
# Written by: DGC
#==============================================================================
class Language(object):
def greet(self):
return self.greeting
#==============================================================================
class English(Language):
def __init__(self):
self.greeting = "Hello"
#==============================================================================
class French(Language):
def __init__(self):
self.greeting = "Bonjour"
#==============================================================================
class Spanish(Language):
def __init__(self):
self.greeting = "Hola"
#==============================================================================
class Multilinguist(object):
def __init__(self, language):
self.greetings = {
"English": "Hello",
"French": "Bonjour",
"Spanish": "Hola"
}
self.language = language
def greet(self):
print(self.greetings[self.language])
#==============================================================================
if (__name__ == "__main__"):
# talking in English
translator = Multilinguist("English")
translator.greet()
# meets a Frenchman
translator.language = "French"
translator.greet()
# greets a Spaniard
translator.language = "Spanish"
translator.greet()