Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Числительное склонение слова, в зависимости от количества
- """
- def f(count, name):
- if count in range(11,15):
- return str(count) + ' ' + name + 'ов'
- else:
- D = [{'':[1]},{'а':[2,3,4]},{'ов':[0,5,6,7,8,9]}]
- def func(count):
- count = str(count)
- for _dict in D:
- for value in _dict.items():
- if int(count[-1]) in value[1]:
- return value[0]
- _end = func(count)
- return str(count) + ' ' + name + _end
- if __name__ == '__main__':
- assert f(0, 'товар') == '0 товаров'
- assert f(1, 'товар') == '1 товар'
- assert f(6, 'товар') == '6 товаров'
- assert f(11, 'товар') == '11 товаров'
- assert f(13, 'товар') == '13 товаров'
- assert f(41, 'товар') == '41 товар'
- assert f(55, 'товар') == '55 товаров'
- assert f(4, 'товар') == '4 товара'
- assert f(44, 'товар') == '44 товара'
- print('All Tests ok')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement