I'm trying to create a function that gives the average of either a list of numbers or just integers as variables. So far I have:
def average(*args):
if type(args) is list:
for x in args:
print sum(x) / float(len(x))
else:
for x in args:
args = list(args)
print sum(x) / float(len(x))
When I input a list, like
average([1, 3, 5, 2])
it works great. But when I enter in
average(1, 3, 5, 2)
it gives "TypeError: 'int' object is not iterable". I've checked other questions but none of the solutions seem to work. I've tried to check if it's a list with type() and isinstance() but whenever I get one of them to work, the other throws out an error.
sum(x)andlen(x)passing a simpleint? Furthermore, try to addprint(type(args))and you will discover that is atuplenot alist