Ask Your Question

# Revision history [back]

### Limit comparison test

Hi! I want to define a function to do limit comparison test. I want the function that can be given one or three arguments. First argument should be the formula for n-th element of sequence I want to put to the test - a. Second, optional, argument should be the formula for n-th element of sequence I want to compare with - b. Third argument should be the letters 'k' or 'd' wether the given sequence b is convergent or divergent.

I have problem to define a function with optional number of arguments. I don't know how to make the program differentiate the number of arguments. I used the nargs command but it does not work.

var('n,b,L')
def limzk(a, *args):
if nargs==0:
b=1/n^2
L=lim(a/b, n=Infinity)
if L<Infinity:
print('convergent')
else:
b=1/n
L=lim(a/b, n=Infinity)
if L>0:
print('divergent')
else:
print('cannot be decided by this test')
elif nargs==2:
if args[1]==('k'):
b=args[0]
L=lim(a/b, n=Infinity)
if L<Infinity:
print('convergent')
else:
print('cannot be decided by this test')
elif args[1]==('d'):
b=args[0]
L=lim(a/b, n=Infinity)
if L>0:
print('divergent')
else:
print('cannot be decided by this test')
else:
print('ERROR: wrong number of parameters given')


Thank you for help.