curriculum/challenges/english/blocks/daily-coding-challenges-python/69a890af247de743333bd4d0.md
Given two timestamps, the first representing when a user finished an exam, and the second representing the current time, determine whether the user can take an exam again.
"YYYY-MM-DDTHH:MM:SS", for example "2026-03-25T14:00:00". Note that the time is 24-hour clock.can_retake("2026-03-23T08:00:00", "2026-03-25T14:00:00") should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(can_retake("2026-03-23T08:00:00", "2026-03-25T14:00:00"), True)`)
}})
can_retake("2026-03-24T14:00:00", "2026-03-25T10:00:00") should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(can_retake("2026-03-24T14:00:00", "2026-03-25T10:00:00"), False)`)
}})
can_retake("2026-03-23T09:25:00", "2026-03-25T09:25:00") should return True.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(can_retake("2026-03-23T09:25:00", "2026-03-25T09:25:00"), True)`)
}})
can_retake("2026-03-25T11:50:00", "2026-03-23T11:49:59") should return False.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(can_retake("2026-03-25T11:50:00", "2026-03-23T11:49:59"), False)`)
}})
def can_retake(finish_time, current_time):
return finish_time
from datetime import datetime, timedelta
def can_retake(finish_time, current_time):
fmt = "%Y-%m-%dT%H:%M:%S"
finished_dt = datetime.strptime(finish_time, fmt)
current_dt = datetime.strptime(current_time, fmt)
diff = current_dt - finished_dt
cooldown = timedelta(hours=48)
return diff >= cooldown