There is a builtin addon for that, no need to reinvent the wheel. Under the User Preferences > Addons make sure Add Mesh : Extra Objects is active.
Then in the 3D view simply press Shift + A > Mesh > Extras > Step Pyramid
You can then adjust the builtin parameters as desired.
Only downsides are that a four sided pyramid seems by default rotated 45° about the Z axis in relation to world coordinates, it also is kind of destructive, in the sense that it can't easily be changed or its parameters adjusted after creation.
As suggested by @batFINGER the Reduce Step By value needs to be twice the Height to obtain "square steps" where the riser matches the tread depth, because as pointed out by Andrew Morton the reduction value is interpreted as a total taking into account both sides and hence divided by two.