Advertisement
tod36

9.1.2. Magic dates

May 2nd, 2020
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # from datetime import date as
  2. # import time as _time
  3. # import python 3.7
  4. import datetime
  5. from datetime import timedelta
  6. from math import floor
  7.  
  8. first_year = int(input())
  9. second_year = int(input())
  10. number_to_search_for = int(input())
  11. found = False
  12.  
  13. date = datetime.datetime(first_year, 1, 1)
  14.  
  15. while date.year <= second_year:
  16.     d1 = floor(date.day / 10)
  17.     d2 = date.day % 10
  18.     d3 = floor(date.month / 10)
  19.     d4 = date.month % 10
  20.     d5 = floor(date.year / 1000)
  21.     d6 = floor(date.year / 100) % 10
  22.     d7 = floor(date.year / 10) % 10
  23.     d8 = date.year % 10
  24.  
  25.     weight = d1*(d2+d3+d4+d5+d6+d7+d8) + \
  26.         d2*(d3+d4+d5+d6+d7+d8) + \
  27.         d3*(d4+d5+d6+d7+d8) + \
  28.         d4*(d5+d6+d7+d8) + \
  29.         d5*(d6+d7+d8) + \
  30.         d6*(d7+d8) + \
  31.         d7*d8
  32.     if weight == number_to_search_for:
  33.         print(str(d1)+str(d2)+"-"+str(d3)+str(d4)+"-"+str(d5)+str(d6)+str(d7)+str(d8))
  34.         found = True
  35.     date = date + timedelta(days=1)
  36. if not found:
  37.     print("No")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement