Hey so Im a beginner, and I need some help.

My professor gave us this code:

def average(list):
     total = 0.0
     for number in list:
          total += number
     return total / len(list)

Then, he asked us to rewrite that program so that it uses a while loop instead.

I have no idea :/ Everything I've tried so far doesn't give me the right answer.

If you could please help me, I'd be forever grateful

Re: HELP! For loops and while loops 80 80
def average(L):
    i=0
    total=0.0
    while i<len(L):
       total+=L[i]
       i+=1
    return total/len(L)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.