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

def average(L):
    i=0
    total=0.0
    while i<len(L):
       total+=L[i]
       i+=1
    return total/len(L)