def screw (thread_code):
    pos_hyphen = thread_code.find('-')
    pos_x = thread_code.find('x')
    if thread_code[0] != 'M' or pos_hyphen == -1 or pos_x == -1 or pos_hyphen > pos_x:
        return 'code error'
    else:
        diameter = int(thread_code[1:pos_hyphen])
        thread_pitch = float(thread_code[pos_hyphen+1:pos_x])
        screw_length = int(thread_code[pos_x+1:])
        return diameter, thread_pitch, screw_length
