public
anonymous / Day of Week
Created

Day of Week

  • Download Gist
Day of Week
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
import easygui as eg
import random
import time
import sys
 
def get_date(difficulty):
if difficulty == 'beginner': year = 2012
elif difficulty == 'easy': year = random.randint(2000,2099)
elif difficulty == 'medium': year = random.randint(1900,2099)
elif difficulty == 'hard': year = random.randint(1583,9999)
month = random.randint(1,12)
if month in (9,4,6,11): day = random.randint(1,30)
elif month == 2:
if year%4==0:
if str(year)[:-2] == '00' and year % 400 ==0:
day = random.randint(1,29)
elif str(year)[:-2] != '00':
day = random.randint(1,29)
else: day = random.randint(1,28)
else: day = random.randint(1,31)
return day,month,year
 
def calculate_day(day,month,year):
#get century day
century = int(str(year)[0:2] +'00')
a = -400
while a <= 9900:
if century == a:
centuryDay = 2 #tuesday
break
a = a+400
a = -300
while a <= 9900:
if century == a:
centuryDay = 0 #sunday
break
a = a+400
a = -200
while a <= 9900:
if century == a:
centuryDay = 5 #friday
break
a = a+400
a = -100
while a <= 9900:
if century == a:
centuryDay = 3 #wednesday
break
a = a+400
#get leapyear
 
if year%4==0 and str(year)[:-2]!='00': leapyear = True
elif year%4==0 and str(year)[:-2]=='00':
if year%400 == 0: leapyear = True
else: leapyear = False
elif year%4 != 0: leapyear = False
 
#get difference
if month == 1:
if leapyear == True:
difference = day - 4
else: difference = day - 3
elif month ==2:
if leapyear == True:
difference = day - 29
else: difference = day - 28
elif month ==3: difference = day
elif month ==4: difference = day - 4
elif month ==5: difference = day - 9
elif month ==6: difference = day - 6
elif month ==7: difference = day - 11
elif month ==8: difference = day - 8
elif month ==9: difference = day - 5
elif month ==10: difference = day - 10
elif month ==11: difference = day - 7
elif month ==12: difference = day - 12
#get dozens, remainder, and fours
shortYear = int(str(year)[-2:])
dozens = shortYear/12
remainder = shortYear - (dozens*12)
fours = remainder/4
#return day of week
dayOfWeek = (difference+centuryDay+dozens+remainder+fours)
while dayOfWeek >=7: dayOfWeek = dayOfWeek - 7
while dayOfWeek < 0: dayOfWeek = dayOfWeek + 7
if dayOfWeek == 0: return 'Sunday'
elif dayOfWeek == 1: return 'Monday'
elif dayOfWeek == 2: return 'Tuesday'
elif dayOfWeek == 3: return 'Wednesday'
elif dayOfWeek == 4: return 'Thursday'
elif dayOfWeek == 5: return 'Friday'
elif dayOfWeek == 6: return 'Saturday'
highscore = 99999999999
difficulty = eg.buttonbox(msg='Choose the difficulty level', title='Guess the date!', choices=('Beginner','Easy','Medium','Hard'), image=None, root=None)
difficulty = difficulty.lower()
while True:
day,month,year = get_date(difficulty)
months = 'January February March April May June July August September October November December'.split()
date = months[month-1]+' '+str(day)+', '+str(year)
days = 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split()
startTime = time.clock()
selection = eg.buttonbox(msg='The date is '+str(date), title='Guess the day!', choices=days, image=None, root=None)
dayOfWeek = calculate_day(day,month,year)
if selection == dayOfWeek:
score = round(time.clock()-startTime,1)
if score < highscore: highscore = score
if eg.ccbox(msg='You are correct! You solved it in '+str(score)+' seconds. Your highscore is '+str(highscore)+' seconds.', title=' ', choices=('Continue', 'Quit'), image=None):
pass
else: sys.exit()
else:
if eg.ccbox(msg='The answer was '+str(dayOfWeek), title=' ', choices=('Continue', 'Quit'), image=None):
pass
else: sys.exit()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.