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 3484516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:47:50+00:00 2026-05-18T10:47:50+00:00

I have a problem: i need to find an average of the list using

  • 0

I have a problem: i need to find an average of the list using this scheme:

First of all, we find an average of two elements, three elements….. len(list) elements and form a new list using averages. The use .pop() and find all averages again. Function should stop when len(list) == 2. Recursion should be used.

Example:
list: [-1, 4, 8, 1]

1 step:

  • find an average of [-1, 4], [-1, 4, 8], [-1, 4, 8, 1]
  • Then we form a new list: [1.5, 3.66..., 3] (averages)
  • Then find averages of new list: [1.5, 3.66...], [1.5, 3.66..., 3]
  • Then we form a new list: [2.5833.., 7.222...] (averages)
  • When len(list) == 2, find an average of this two elements.

Answer is 2.652777.

What should i write:

jada = []

while True:    
    print 'Lst elements:'    
    a = input()
    if (a == ''):    
        break    
    jada.append(a)

print 'Lst is:' + str(Jada)

def keskmine(Jada):
    for i in range(len(Jada) - 1):
        ...

    jada.pop()
    return keskmine(Jada)

Actually, this is a part of a homework, but i don’t know how to solve it.

  • 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-05-18T10:47:50+00:00Added an answer on May 18, 2026 at 10:47 am

    In short, you’re finding the “running average” from a list of numbers.

    Using recursion would be helpful here. Return the only element when “len(lst) == 1” otherwise, compute the running average and recurse.

    There are two parts in this assignment. First, you need to transform lists like [-1, 4, 8, 1] to lists like [1.5, 3.66, 3] (find the running averages). Second, you need to repeat this process with the result of the running averages until your list’s length is 2 (or 1).

    You can tackle the first problem (find the running averages) independently from the second. Finding the running average is simple, you first keep track of the running sum (e.g. if the list is [-1, 4, 8, 1] the running sum is [-1, 3, 11, 12]) and divide each elements by their respective running index (i.e. just [1, 2, 3, 4]), to get [-1/1, 3/2, 11/3, 12/4] = [-1, 1.5, 3.66, 3]. Then you can discard the first element to get [1.5, 3.66, 3].

    The second problem can be easily solved using recursion. Recursion is just another form of looping, all recursive code can be transformed to a regular for/while-loops code and all looping code can be transformed to recursive code. However, some problems have a tendency towards a more “natural” solution in either recursion or looping. In my opinion, the second problem (repeating the process of taking running averages) is more naturally solved using recursion. Let’s assume you have solved the first problem (of finding the running average) and we have a function runavg(lst) to solve the first problem. We want to write a function which repeatedly find the running average of lst, or return the average when the lst’s length is 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: I need to find all active [GiftPledges] that have the last three
I have the following problem: We need to find the next august. I other
I have a problem with reflection. I need to find the type that instantiates
I have a problem where I need to remove all code and triggers from
I have a problem. I need to trace all read/write operations to the registry
Description of my problem: I have a sample audio file and need to find
I am designing reports using freemarker, I have a problem where I need the
I need some help in this problem I have this matrix in MATLAB: A
I have a problem I just can't fix. I need to find if a
I need help for this problem. In MYSQL Table i have a field :

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.