usr bin python -coding utf-8- def human num words delta_string num las

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/python
#-*-coding:utf-8-*-
def human(num, words = []):
delta_string = "%s" % num
last_element = int(delta_string[len(delta_string)-1])
if last_element > 0 and last_element < 2:
tmp = words[0]
elif last_element > 1 and last_element < 5:
tmp = words[1]
else:
tmp = words[2]
return "%s %s" % (num, tmp)
sec = 55
print human(sec, [u'секунда', u'секунды', u'секунд'])