Good afternoon, I wanted to ask more experienced people if there is a method for passing an argument to a function as an index. Thank you in advance!!
def planting_plan(rows):
i = list(range(0,10+1,2))
er = i[5] # it is very necessary to pass instead of [5] - [rows], I broke my head how to do it
return er
print(planting_plan(5))
print(type(planting_plan(5)))
result:10 <class 'int'>
expected result:10<class 'list'>
>Solution :
This function is completely useless, since you are not using the argument rows anywhere, so the result will be 10 even if you call it with a number != 5.
If you replace [5] with [rows] then your function will change dinamically based on the value of rows and, like so, you’re passing the index:
def planting_plan(rows):
i = list(range(0,10+1,2))
er = i[rows]
return er
So, passing [rows] instead of [5] is not actually "neccessary", but it would not make much sense to write a function with a fixed value instead of passing a dinamic one.