Skip to content

Instantly share code, notes, and snippets.

@CubexX
Created July 13, 2018 22:15
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save CubexX/182bd5918d3455d986b354eadaea02ce to your computer and use it in GitHub Desktop.
Save CubexX/182bd5918d3455d986b354eadaea02ce to your computer and use it in GitHub Desktop.
Python plural russian days / Склонение день/дня/дней
def plural_days(n):
days = ['день', 'дня', 'дней']
if n % 10 == 1 and n % 100 != 11:
p = 0
elif 2 <= n % 10 <= 4 and (n % 100 < 10 or n % 100 >= 20):
p = 1
else:
p = 2
return str(n) + ' ' + days[p]
@Bor1sych
Copy link

Спасибо, хороший код

@Yessirskiy
Copy link

Спасибо! Хорошая работа, здорово помогло!

@trankov
Copy link

trankov commented Aug 15, 2021

С вашего позволения подсократил переменные и операторы. Ну и возвращать, мне кажется, правильнее без числа. Спасибо за прекрасное решение, очень мне помогло.

words = ['день', 'дня', 'дней']

if all((value % 10 == 1, value % 100 != 11)):
    return words[0]
elif all((2 <= value % 10 <= 4,
          any((value % 100 < 10, value % 100 >= 20)))):
    return words[1]
return words[2]

@Kycko
Copy link

Kycko commented Dec 3, 2021

Perfect! 😍😋

@lilrock1981
Copy link

Very good!!!!!!

@mafiStudios
Copy link

thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment