Skip to content

Instantly share code, notes, and snippets.

@cammckinnon
Created February 12, 2012 18:01
Show Gist options
  • Save cammckinnon/1809939 to your computer and use it in GitHub Desktop.
Save cammckinnon/1809939 to your computer and use it in GitHub Desktop.
def ArithGeo(arr):
diff = arr[1] - arr[0]
multiple = arr[1]/arr[0]
isarith = True
isgeom = True
for i in range(0,len(arr)-1):
d = arr[i+1] - arr[i]
if d!=diff:
isarith = False
m = arr[i+1] / arr[i]
if m!=multiple:
isgeom = False
if isarith:
print "Arithmetic"
elif isgeom:
print "Geometric"
else:
print -1
# this call is needed to test your function
# keep this when you submit your code
ArithGeo(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment