Here is a program that fulfills the requirements:
class TimeFormatMistake(Exception):
pass
while True:
try:
hour = int(input("Hour: "))
minute = int(input("Minute: "))
if hour > 23 or minute > 59:
raise TimeFormatMistake
if hour == 0 or hour == 12:
hour_str = "12"
elif hour < 12:
hour_str = str(hour)
else:
hour_str = str(hour-12)
if minute < 10:
minute_str = "0" + str(minute)
else:
minute_str = str(minute)
print(f"That is {hour_str}:{minute_str} { 'AM' if hour < 12 else 'PM'}")
except TimeFormatMistake:
print("There is no such time as {}:{} ".format(hour, minute))
again = input("Again (y/n)? ")
if again.lower() != 'y':
print("Good-bye")
break