Jump to content

Trouble using Functions

- - - - -

  • Please log in to reply
1 reply to this topic

#1
kmaj

kmaj

    Newbie

  • Members
  • Pip
  • 1 posts
Hey guys, I have a question that I am a list of numbers and I need to use functions to find the average. I think I pretty much have it, but I can not get it to print the average. Can you please tell me what is wrong.

def average(nums):

nums = [30,34,40,36,36,28,29,32,34,44,36,35,28,33,29,40,36,24,26,30,30,32,34,32,28,36,24,32]
return sum(nums) / len(nums)

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 890 posts
  • Location:::1

def average(nums):

    return sum(nums) / len(nums)


nums = [30,34,40,36,36,28,29,32,34,44,36,35,28,33,29,40,36 ,24,26,30,30,32,34,32,28,36,24,32]

print average(nums)

Seems you've mixed your code slightly.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users