You can use the normal output from the "Texture Coordinate" node, then extract the z value. A value of 0 means the normal is orthogonal to the vertical axis, a value of 1 means the face is horizontal, facing up, and a value of -1 means the face is horizontal, facing down.
Shade smooth, shade flat, and wireframe in [-1;1] :
Shade smooth, shade flat, and wireframe in absolute [0;1] mode :
As pointed out in the comments by @Robin Betts, this will give you the normal in local space. It means if you rotate your object, but don't apply the transform, the color of each face will stay the same. If you want your shading to be applied in world space, you should use the normal output from the "Geometry" node.
Top row : World space, using the "Geometry" node
Bottom row : Object space, using the "Texture coordinate" node.
Rotation is not applied in both rows.