-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdigit_names.py
executable file
·42 lines (31 loc) · 1.35 KB
/
digit_names.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
#!/usr/bin/env python3
# Copyright (c) 2008-11 Qtrac Ltd. All rights reserved.
# This program or module is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. It is provided for educational
# purposes and is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
import sys
Language = "en"
ENGLISH = {0: "zero", 1: "one", 2: "two", 3: "three", 4: "four",
5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine"}
FRENCH = {0: "zero", 1: "un", 2: "deux", 3: "trois", 4: "quatre",
5: "cinq", 6: "six", 7: "sept", 8: "huit", 9: "neuf"}
def main():
if len(sys.argv) == 1 or sys.argv[1] in {"-h", "--help"}:
print("usage: {0} [en|fr] number".format(sys.argv[0]))
sys.exit()
args = sys.argv[1:]
if args[0] in {"en", "fr"}:
global Language
Language = args.pop(0)
print_digits(args.pop(0))
def print_digits(digits):
dictionary = ENGLISH if Language == "en" else FRENCH
for digit in digits:
print(dictionary[int(digit)], end=" ")
print()
main()