-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_7_step_3_elif.py
36 lines (31 loc) · 1.52 KB
/
lab_7_step_3_elif.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
import json
# A defined list of languages supported by Amazon Translate
languages = ["af","sq","am","ar","az","bn","bs","bg","zh","zh-TW","hr","cs","da","fa-AF","nl","en","et","fi","fr","fr-CA","ka","de","el","ha","he","hi","hu","id","it","ja","ko","lv","ms","no","fa","ps","pl","pt","ro","ru","sr","sk","sl","so","es","sw","sv","tl","ta","th","tr","uk","ur","vi"]
# This uses a json string as an input
json_string = """
{
"Input":[
{
"Text":"I am learning to code in AWS",
"SourceLanguageCode":"en",
"TargetLanguageCode":"fr"
}
]
}
"""
json_input = json.loads(json_string)
SourceLanguageCode = json_input['Input'][0]['SourceLanguageCode']
TargetLanguageCode = json_input['Input'][0]['TargetLanguageCode']
# Uses an if-elif-else statements to check that the SourceLanguageCode is in the languages list.
if SourceLanguageCode == TargetLanguageCode:
print("The SourceLanguageCode is the same as the TargetLanguageCode - nothing to do")
elif SourceLanguageCode not in languages and TargetLanguageCode not in languages:
print("Neither the SourceLanguageCode and TargetLanguageCode are valid - stopping")
elif SourceLanguageCode not in languages:
print("The SourceLanguageCode is not valid - stopping")
elif TargetLanguageCode not in languages:
print("The TargetLanguageCode is not valid - stopping")
elif SourceLanguageCode in languages and TargetLanguageCode in languages:
print("The SourceLanaguageCode and TargetLanguageCode are valid - proceeding")
else:
print("There is an issue")