question 58 Strings & Text · medium
Check a delivery time
A delivery form asks for a time slot as HH:MM on a 24-hour clock, and the text box accepts anything. Before converting anything with int, check the format: exactly 5 characters, a : at position 2, and digits everywhere else. Print invalid: format if the format is wrong. Then check the numbers: print invalid: hour for an hour above 23 and invalid: minute for a minute above 59. Otherwise print valid.
Input
slot, the text typed in the boxFormat5 characters,
: at position 2, the other four characters 0–9Prints
invalid: format, invalid: hour, invalid: minute or valid, in that order of checkingExamples
"07:45" → valid; "24:00" → invalid: hour; "7:45" → invalid: formatExpected output1 line
- 1valid