runtime
58 / 500
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.

Inputslot, the text typed in the box
Format5 characters, : at position 2, the other four characters 0–9
Printsinvalid: format, invalid: hour, invalid: minute or valid, in that order of checking
Examples"07:45" → valid; "24:00" → invalid: hour; "7:45" → invalid: format
Expected output1 line
  1. 1valid

Loading your progress…

Check a delivery time — Python practice · Runtime