I tried so many things to do this task. I have no idea why doesn't it work. Please help!
'''Create a function in Python that accepts two parameters. The first will be a list of numbers. The second parameter will be a string that can be one of the following values: asc, desc, and none.
If the second parameter is "asc," then the function should return a list with the numbers in ascending order. If it's "desc," then the list should be in descending order, and if it's "none," it should return the original list unaltered '''
def func(*args, str):
list1=args
if str == 'asc':
a = sorted(list1,reverse=False)
print(a)
elif str == 'desc':
b = sorted(list1,reverse=True)
print(b)
else:
print(list1)
l = [2,3,7,6,5]
m = 'asc'
print(func(l,m))
I know that I also have to do 'none' for str, but I don't know how
return
from this function. Replace all theprint(...)
in your function code withreturn ...
. And your*args
parameter should just beargs
. \$\endgroup\$