Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Last active May 8, 2020 20:21
Show Gist options
  • Save kurzweil777/3e54760300753ea65a764f58029e86f1 to your computer and use it in GitHub Desktop.
Save kurzweil777/3e54760300753ea65a764f58029e86f1 to your computer and use it in GitHub Desktop.
LetPy
import datetime
try:
date_x = (input("Введите дату/время в формате ДД.ММ.ГГГГ ЧЧ:ММ : "))
date_x = datetime.datetime.strptime(date_x, '%d.%m.%Y %H:%M')
date_x_new = date_x.replace(minute=date_x.minute + 1)
if date_x < datetime.datetime.now():
print("Ошибка")
exit()
else:
pass
except (ValueError, NameError):
print("Ошибка")
exit()
def choose_plural(quantity, list_one=()):
g = str(quantity)
last_digit = int(g[-1])
quantity_ = quantity % 100
if quantity_ in range(10, 20):
return quantity, list_one[2]
elif last_digit >= 5 or last_digit == 0:
return quantity, list_one[2]
elif last_digit in range(2, 5):
return quantity, list_one[1]
else:
return quantity, list_one[0]
time_delta = date_x_new - datetime.datetime.now()
time_delta_minutes = round(time_delta.total_seconds() % 3600 // 60)
time_delta_hours = round(time_delta.seconds // 3600)
type_of_minute = choose_plural(time_delta_minutes, ('минута', 'минуты', 'минут'))
type_of_hour = choose_plural(time_delta_hours, ('час', 'часа', 'часов'))
type_of_day = choose_plural(time_delta.days, ('день', 'дня', 'дней'))
if time_delta_hours < 1 and time_delta.days == 0:
print("До часа \"Икс\" " + (str(time_delta_minutes)) + " " + type_of_minute[1])
while time_delta_hours > 1 and time_delta.days < 1:
if time_delta_minutes == 0:
print("До часа \"Икс\" " + (str(time_delta_hours)) + " " + type_of_hour[1])
break
print("До часа \"Икс\" " + (str(time_delta_hours)) + " " + type_of_hour[1] + " и "
+ (str(time_delta_minutes)) + " " + type_of_minute[1])
break
while time_delta.days >= 1:
if time_delta_hours == 0:
print("До часа \"Икс\" " + (str(time_delta.days)) + " " + type_of_day[1])
break
print("До часа \"Икс\" " + (str(time_delta.days)) + " " + type_of_day[1] + " и "
+ (str(time_delta_hours)) + " " + type_of_hour[1])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment