Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:02:58+00:00 2026-06-17T08:02:58+00:00

def summation(calc_termo, linf, prox, lsup): soma = 0 while linf <= lsup: soma =

  • 0
def summation(calc_termo, linf, prox, lsup):
    soma = 0
    while linf <= lsup:
        soma = soma + calc_termo(linf)
        linf = prox(linf)
    return soma
summation(lambda x: summation(lambda x: x, 1, lambda x: x + 1, x),1, lambda x: x + 1, 5)

I’m having trouble to understand how this code works. I got this as an exercise from my university and I’m having some trouble understanding the code.

It seems to be the sum of the numbers between 1 to 5, but can’t understand what summation(lambda x: x, 1, lambda x: x + 1, x) does.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:02:59+00:00Added an answer on June 17, 2026 at 8:02 am

    I’d start by taking those arguments apart:

    lambda x: summation(lambda x: x, 1, lambda x: x + 1, x)
    

    Substitute those variables back into the the original functions and simplify it:

    def inner_function(x):
        soma = 0
        linf = 1
    
        while linf <= x:
            soma += linf + 1
            linf += 1
    
        return soma
    

    Simplify that a little more:

    def inner_function(x):
        soma = 0
    
        for linf in range(1, x + 1):
            soma += linf
    
        return soma
    

    And a little more:

    inner_function = lambda x: sum(range(1, x + 1))
    

    And some more:

    inner_function = lambda x: x * (x + 1) / 2
    

    Now your original function becomes:

    def summation(calc_termo, linf, prox, lsup):
        soma = 0
    
        while linf <= lsup:
            soma = soma + calc_termo(linf)
            linf = prox(linf)
    
        return soma
    
    summation(inner_function, 1, lambda x: x + 1, 5)
    

    Or:

    def summation(linf, prox, lsup):
        soma = 0
    
        while linf <= lsup:
            soma = soma + linf * (linf + 1) / 2
            linf = prox(linf)
    
        return soma
    
    summation(1, lambda x: x + 1, 5)
    

    You can take it from there. I got:

    summation = lambda: sum(n * (n + 1) / 2 for n in range(6))
    

    Which is equal to:

    sum(sum(range(n + 1)) for n in range(6))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if
def cmd = array [ 0x0F, 0x03 ] this code defines array of integers
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def record return unless @supported klasses = profile_options[:formats].map { |f| RubyProf.const_get(#{f.to_s.camelize}Printer) }.compact klasses.each do
def makecounter(): return collections.defaultdict(int) class RankedIndex(object): def __init__(self): self._inverted_index = collections.defaultdict(list) self._documents = []
def divideset(rows, column, value) split_function = nil if value.is_a?(Fixnum) || value.is_a?(Float) split_function = lambda{|row|
def add app @has_app[app] = true @apps << app end In the code above
def foo f = Proc.new { return return from foo from inside proc }
def validate(request, *args, **kwargs): form_class = kwargs.pop('form_class') extra_args_func = kwargs.pop('callback', lambda request, *args, **kwargs:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.