Conduct of arguments between minimum and maximum arguments
-
Purpose: Write an arbitrary number of arguments and repetition of arguments between the minimum and maximum arguments. If the function is transferred to an empty list of arguments, it must return the meaning
None
♪ In the decision not to use design change*args
on the list or other data structure.def min_max(*args): composition = 1 max_arg = args[0] max_ind = 0 min_arg = args[0] min_ind = 0 # Проходит по списку и вычисляет max и min for i, item in enumerate(args): if item > max_arg: max_arg = item max_ind = i if item < min_arg: min_arg = item min_ind = i for i in args[min_ind:max_ind]: composition *= i return composition
if name == 'main':
arg = list(map(float, input('Введите список аргументов: ').split()))
print("Произведение аргументов, расположенных"
" между минимальным и максимальным аргументами: ",
min_max(*arg))
Problem is, if you try to remove an empty list, it makes a mistake.
IndexError
What's the mistake?
-
'Cause you're going straight into it.
args[0]
which does not existUse the test initially on empty parameters:
def min_max(*args): if args == (): return None
or
def min_max(*args): if len(args) == 0: return None