Code for calculating partition function from energyeigenvalue?

I didn’t find any proper code regarding this both for degenerate or non degenerate.