Advertisement
dmemsm

Задача 3

Jan 12th, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. # https://lifehacker.ru/kakoj-den-nedeli
  2.  
  3. day = int(input("День: "))
  4. month = int(input("Месяц: "))
  5. year = int(input("Год: "))
  6.  
  7.  
  8. def is_year_leap(year_num):
  9.     return (year_num % 4 == 0 and year_num % 100 != 0) or (year_num % 400 == 0)
  10.  
  11.  
  12. def get_month_code(month_num, year_num):
  13.     if month_num == 1:
  14.         if is_year_leap(year_num):
  15.             return 0
  16.         else:
  17.             return 1
  18.     elif month_num == 2:
  19.         if is_year_leap(year_num):
  20.             return 3
  21.         else:
  22.             return 4
  23.     elif month_num == 3:
  24.         return 4
  25.     elif month_num == 4:
  26.         return 0
  27.     elif month_num == 5:
  28.         return 2
  29.     elif month_num == 6:
  30.         return 5
  31.     elif month_num == 7:
  32.         return 0
  33.     elif month_num == 8:
  34.         return 3
  35.     elif month_num == 9:
  36.         return 6
  37.     elif month_num == 10:
  38.         return 1
  39.     elif month_num == 11:
  40.         return 4
  41.     elif month_num == 12:
  42.         return 6
  43.  
  44.  
  45. def get_century_code(year_num):
  46.     n = year_num // 100 % 4
  47.     if n == 0:
  48.         return 6
  49.     elif n == 1:
  50.         return 4
  51.     elif n == 2:
  52.         return 2
  53.     elif n == 3:
  54.         return 0
  55.  
  56.  
  57. def get_year_code(year_num):
  58.     return (get_century_code(year_num) + year_num % 100 + year_num % 100 // 4) % 7
  59.  
  60.  
  61. result = (day + get_month_code(month, year) + get_year_code(year)) % 7
  62. if result == 2:
  63.     print("Понедельник")
  64. elif result == 3:
  65.     print("Вторник")
  66. elif result == 4:
  67.     print("Среда")
  68. elif result == 5:
  69.     print("Четверг")
  70. elif result == 6:
  71.     print("Пятница")
  72. elif result == 0:
  73.     print("Суббота")
  74. elif result == 1:
  75.     print("Воскресенье")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement