How do I write a function that changes current frame to 150 if current frame is 250
Scene.frame_set(...)

All handlers take a single argument, scene. In some handlers, load for example, the scene argument has value None in which case is often referred to as "dummy"

import bpy

def skip_playback(scene):
    if scene.frame_current &gt;= 250:
        scene.frame_set(150)

bpy.app.handlers.frame_change_pre.append(skip_playback)


The scene in the handler is the scene being "handled"..  Using a data reference like bpy.data.scenes["Scene"] is a slippery slope, when there is no scene named  "Scene" or there is another scene's handler will set its frame.

Similar functionality could be achieved by setting the scene frame start and end, or preview start and end.

On your error, it is a basic syntax error in that you have not defined scene in the change_frame method.

I would recommend, when you are new (or not) to python,  when you get an error you don't understand make a search for "Python NameError"  (based on the error type NameError in this case)