compute the sum of squres

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eaner51
    New Member
    • Oct 2007
    • 1

    #1

    compute the sum of squres

    if the variable is m how the while loop can compute sum of squre of first five continuing numbers.how it can associate the sum with total
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by eaner51
    if the variable is m how the while loop can compute sum of squre of first five continuing numbers.how it can associate the sum with total
    Please post what you have tried on that and be a little more specific.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by eaner51
      if the variable is m how the while loop can compute sum of squre of first five continuing numbers.how it can associate the sum with total
      You may want something like this:[CODE=python]
      >>> sumofsqs = 0
      >>> i = 0
      >>> while i < 5:
      ... i += 1
      ... sumofsqs += i*i
      ...
      >>> print sumofsqs
      55
      >>> [/CODE]
      Please note the use of CODE tags. Instructions are on the right hand side of the page while you are posting. Thanks.
      Last edited by bartonc; Oct 21 '07, 07:46 PM.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        [code=Python]
        >>> series = (3,6,9,12,15,18 ,21,24)
        >>> total = sum([series[i]**2 for i in range(5)])
        >>> total
        495
        >>> [/code]

        Comment

        Working...