Advertisement
m2ansib

Pointers - Sprints (Days 14 & 15)

Jun 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. def isLeap(year):
  2.     ____
  3.  
  4. # [CLUE] ^ Define 'isLeap()' before proceeding.
  5. # [CLUE] ^ Only include years that are divisible by 4 or are centuries divisible by 400.
  6.  
  7. def whatday(date,mth,year=2017):
  8.     #your code here
  9.     mths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  10.     weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  11.  
  12.     # dimth: List of total days in month.
  13.     dimth = [___] # [CLUE] Number of days in each month. You may substitute any number for Feb for now.
  14.  
  15.     if not isLeap(year):
  16.         dimth[___] = 28 # [CLUE] Refer to the indices in 'mths'.
  17.     else:
  18.         dimth[___] = 29 # [CLUE] Same index as above.
  19.    
  20.     mth = mths.index(mth) + ___
  21.     # ^ [CLUE] Convert the month name to its equivalent numeral ('Feb' gives 2, 'Mar' gives 3).
  22.     # ^ [CLUE] Recall that list indices start from zero.
  23.  
  24.     offset = -2
  25.    
  26.     days = 0
  27.     for y in range(year):
  28.         if isLeap(y):
  29.             days += ___ # [CLUE] How many days are there in a leap year?
  30.         else:
  31.             days += ___ # [CLUE] How many days are there in a non-leap year?
  32.     for m in range(mth-1):
  33.         days += ___[_]
  34.         # [CLUE] ^ Use the list of days in months to find the number of days passed.
  35.         # [CLUE] ^ The index to use has been adjusted for you.
  36.  
  37.     return weekdays[(
  38.         offset
  39.         + days
  40.         + date
  41.         ) % 7]
  42.  
  43. for item in [
  44.     (1,'Jun'), # Thu
  45.     (28,'Feb'), # Tue
  46.     (31,'Dec'), # Sun
  47.     (12,'Dec',2017), # Tue
  48.     (14,'Feb',2021), # Sun
  49.     (31,'Dec',2055) # Fri
  50. ]:
  51.     print(item, whatday(*item))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement