from datetime import date
today = date(2026, 11, 30)
exams = {"Python": date(2026, 12, 18), "SQL": date(2027, 1, 7), "DSA": date(2027, 2, 1)}
for subject, day in sorted(exams.items(), key=lambda kv: kv[1]):
left = (day - today).days
weeks, days = divmod(left, 7)
print(f"{subject:<7}{day:%d %b %Y} ({day:%A}): {left} days = {weeks} weeks {days} days")
Output Verified by running it on Python 3
Python 18 Dec 2026 (Friday): 18 days = 2 weeks 4 days
SQL 07 Jan 2027 (Thursday): 38 days = 5 weeks 3 days
DSA 01 Feb 2027 (Monday): 63 days = 9 weeks 0 days
Subtracting dates gives a timedelta; .days is an int. Format codes such as %d %b %Y and %A work directly in f-strings.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!