Created
July 13, 2018 22:15
-
-
Save CubexX/182bd5918d3455d986b354eadaea02ce to your computer and use it in GitHub Desktop.
Python plural russian days / Склонение день/дня/дней
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Спасибо! Хорошая работа, здорово помогло!
С вашего позволения подсократил переменные и операторы. Ну и возвращать, мне кажется, правильнее без числа. Спасибо за прекрасное решение, очень мне помогло.
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]
Perfect! 😍😋
Very good!!!!!!
thx.
I did something, I didn’t do something, thanks to everyone, here’s the shortest (it seems to me) code
def plural_days(days: int):
if days % 10 == 1 and days % 100 != 11:
return f"{days} день"
elif 2 <= days % 10 <= 4 and (days % 100 < 10 or days % 100 >= 20):
return f"{days} дня"
return f"{days} дней"
😁😁😁
def plural_days(days: int):
if days % 10 == 1 and days % 100 != 11:
return f"{days} день"
return f"{days} дня" if 2 <= days % 10 <= 4 and (days % 100 < 10 or days % 100 >= 20) else f"{days} дней"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Спасибо, хороший код