A relatively more complex regex problem to work on. It is fun!
import re n = input() for _ in range(n): str = raw_input() pl = '[+-]?([1-8]?[0-9]([.][0-9]+)?|[9][0]([.][0]+)?)' pr = '[+-]?(([1-9]?[0-9]([.][0-9]+)?)|([1][0-7][0-9]([.][0-9]+)?)|([1][8][0]([.][0]+)?))' p = '^[(]' + pl + ',s' + pr + '[)]$' m = re.search(p, str) print ("Valid" if m != None else "Invalid")