Counting the number of Alive particles
Use the dependency graph.
import bpy

# get the object
obj = bpy.context.object

# get current dependency graph
dg = bpy.context.evaluated_depsgraph_get()

# get the object as currently evaluated
e_obj = obj.evaluated_get(dg)

# get the particle system
ps = e_obj.particle_systems.active

# and count
print(len([p for p in ps.particles if p.alive_state == 'ALIVE']))

As said in the documentation:

This example demonstrates access to the evaluated ID (such as object,
material, etc.) state from an original ID. This is needed every time
one needs to access state with animation, constraints, and modifiers
taken into account.