this is a pure python implementation of the pseries algorithm https en wikipedia orgwikiharmonicseriesmathematicspseries for doctests run following command python m doctest v pseries py or python3 m doctest v pseries py for manual testing run python3 pseries py pure python implementation of pseries algorithm return the pseries starting from 1 to last nth term examples pseries5 2 1 1 4 1 9 1 16 1 25 pseries5 2 pseries5 2 1 1 0 25 1 0 1111111111111111 1 0 0625 1 0 04 pseries 1000 pseries0 0 pseries1 1 1 pure python implementation of p series algorithm return the p series starting from 1 to last nth term examples p_series 5 2 1 1 4 1 9 1 16 1 25 p_series 5 2 p_series 5 2 1 1 0 25 1 0 1111111111111111 1 0 0625 1 0 04 p_series 1000 p_series 0 0 p_series 1 1 1
from __future__ import annotations


def p_series(nth_term: float | str, power: float | str) -> list[str]:
    
    if nth_term == "":
        return [""]
    nth_term = int(nth_term)
    power = int(power)
    series: list[str] = []
    for temp in range(int(nth_term)):
        series.append(f"1 / {pow(temp + 1, int(power))}" if series else "1")
    return series


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    nth_term = int(input("Enter the last number (nth term) of the P-Series"))
    power = int(input("Enter the power for  P-Series"))
    print("Formula of P-Series => 1+1/2^p+1/3^p ..... 1/n^p")
    print(p_series(nth_term, power))