python 3.x - How I add values in a list I am using as the parameter for a function? -


i trying understand these instructions.

  1. set new function in main program file named “summer” takes list parameter , returns value determine in next steps.

  2. in “summer” function, set loop uses counter variable named “n” take on values 0, 2, 4, 6, 8, 10, 12.

  3. each time through loop, call “powerval” function “mymath” module passing parameters item “n” , “n+1” list of data passed “summer”. add these values , return final result caller.

so far have:

def summer(list):     n in range(0,13,2):         value=powerval(n,n+1) 

after lost. how perform step 3?

you need add them up:

from mymath import powerval  def summer(lst):     total = 0      n in range(0, 13, 2):         total += powerval(lst[n], lst[n + 1])      return total 

i'm not sure use lst (i renamed list lst, list built-in function), i'm guessing you're trying nth , n + 1th elements list.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -