File size: 735 Bytes
f1f2c2c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import re
def output_from_text(text):
#extract the number in the last line of text
try:
lines = text.strip().split("\n")
lines = list(filter(None, lines))
pattern = r'^[^a-zA-Z0-9\s]+$'
lines = [s for s in lines if not re.fullmatch(pattern, s)]
answer = -1
answer = int(re.findall(r"\b\d+\b", lines[-1])[0])
if answer != -1:
return {
"OUTPUT": answer,
"ERROR": None
}
else:
return{
"OUTPUT": None,
"ERROR": 'Does not give correct format'
}
except Exception as e:
return {
"OUTPUT": None,
"ERROR": str(e)
} |