Skip to content

Instantly share code, notes, and snippets.

@dnorhoj
Created March 8, 2022 20:12
Show Gist options
  • Save dnorhoj/2a0f360118d21d25a0fa10b196f3b8ef to your computer and use it in GitHub Desktop.
Save dnorhoj/2a0f360118d21d25a0fa10b196f3b8ef to your computer and use it in GitHub Desktop.
Weekday guessing game.
from random import randrange
from datetime import datetime
from time import time
from colorama import init
init()
from termcolor import cprint, colored
START_DATE = datetime(year=2022, month=1, day=1)
END_DATE = datetime(year=2023, month=1, day=1)
DAYS = [
["1", "monday", "mon"],
["2", "tuesday", "tue"],
["3", "wednesday", "wed"],
["4", "thursday", "thu"],
["5", "friday", "fri"],
["6", "saturday", "sat"],
["7", "sunday", "sun"],
]
while True:
timestamp = randrange(START_DATE.timestamp(), END_DATE.timestamp())
date = datetime.fromtimestamp(timestamp)
cprint(date.strftime("%B %d, %Y"), "magenta")
timer = time()
in_ = input(colored("$> ", "magenta"))
if in_.strip().lower() in DAYS[date.weekday()]:
cprint("Nice!", "green")
cprint(f"Your time was {round(time()-timer, 2)} seconds.", "green")
else:
cprint(f"Nope! The correct answer was {DAYS[date.weekday()][1].capitalize()}.", "red")
print("\n")
termcolor
colorama
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment