Write a Python function to check if a number is a power of a given base.


Topic: Write a Python function to check if a number is a power of a given base.

Solution

import math
def isPower (n, base):
    if base == 1 and n != 1:
        return False
    if base == 1 and n == 1:
        return True
    if base == 0 and n != 1:
        return False
    power = int (math.log(n, base) + 0.5)
    return base ** power == n



List all Python Programs