The First Folio separated Shakespeare's plays into tragedy,comedy and historical genres, possibly because Shakespeare himself supported such a selection of theatrical genres; Polonius declaring in Hamlet the arrival of "the best actors in the world, either for tragedy,comedy, history...".
Shakespeare has written a total of thirty-seven plays, however no one can know for certain because of the inexact documentation at the time the plays were first being organised and published. If we count Cardenio and Love's Labour's Won, then we could say he either wrote alone or in collaboration, forty plays.