Created
March 8, 2022 20:12
-
-
Save dnorhoj/2a0f360118d21d25a0fa10b196f3b8ef to your computer and use it in GitHub Desktop.
Weekday guessing game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
termcolor | |
colorama |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment