Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import random
import calendar
import datetime
try:
input = raw_input
except NameError:
pass
def random_date(start_year, end_year):
"""Generate a random date between `start` and `end`"""
# Based on https://stackoverflow.com/a/8170651
start = datetime.datetime(start_year, 1, 1)
end = datetime.datetime(end_year, 12, 31, 23, 59, 59)
return (start + datetime.timedelta(
# Get a random amount of seconds between `start` and `end`
seconds=random.randint(0, int((end - start).total_seconds())),
)).date()
def get_weekday_name(date):
return calendar.day_name[date.weekday()].lower()
def check(date, user_input):
weekday_name = get_weekday_name(date)
return len(user_input) >= 3 and weekday_name.startswith(user_input.lower())
try:
guess_date = random_date(1900, 2099)
user_input = input(str('[Guess the week day] {}: '.format(guess_date)))
if check(guess_date, user_input):
print('YEAH!')
else:
print('WRONG!! correct is: {}, keep training :)'
.format(get_weekday_name(guess_date)))
except KeyboardInterrupt:
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.