How do you play an animation with code?
The script that plays an animation is something like this:

import bpy
bpy.ops.screen.animation_play()


In the future, if you want to use python to do something, you can make it easier by activating Python Tooltips, which you can do by going to Edit >> Preferences >> Interface >> Python Tooltips. You can see Python Tooltips in action by hovering over a button like the Play Animation button.