Reading Time: 1 minutes
Check for Geometric Progression in Python
Write a Python function which accepts a list of terms and tells the user whether these terms make up a Geometric Progression or not.
Geometric Progression
def gpChecker(listOfTerms): if len(listOfTerms) <= 1: return True commonRatio = listOfTerms[1] / float(listOfTerms[0]) for index in range( 1, len(listOfTerms) ): if listOfTerms[index] / float(listOfTerms[index - 1]) != commonRatio: return False return True print(gpChecker([3, 12, 48, 192])) # True