Funny and useful scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
837 B

#!/usr/local/bin/python3
import time
from num2words import num2words
def pluralize(n, forms):
"""
Returns appropriate form of item that should be after its quantity
:param n: number of items
:param forms: array of 3 forms for 1, 2 and 5 counts
('яблоко', 'яблока', 'яблок')
:returns
"""
if n % 100 in (11, 12, 13, 14):
return forms[2]
if n % 10 == 1:
return forms[0]
if n % 10 in (2, 3, 4):
return forms[1]
return forms[2]
H = time.localtime(time.time()).tm_hour
M = time.localtime(time.time()).tm_min
W = num2words(H, lang = 'ru', gender = 'm') + pluralize(H, [' час, ', ' часа, ', ' часов, '])
W = W + num2words(M, lang = 'ru', gender = 'f') + pluralize(M, [' минута', ' минуты', ' минут'])
print(W)