Question: there's an example in Learn Python The Hard Way -- Python -- That I'm working on and I just couldn't quite think through it. I think I'm hiccuping on the theoretical elements of changing the program more than the writing the physical lines, but I could be completely wrong.

```
i = 0
numbers =[]
while i < 6:
    print "At the top i is %d" %i
    numbers.append(i)

    i += 1
    print "Numbers now: ", numbers
    print "At the bottom i is %d" %i

print "The numbers: "
for num in numbers:
    print num

```

This is the code that I'm working with and the question/ prompt reads as follows: 

> 
> Convert this while-loop to a function that you can call, and replace 6 in the test (i < 6) with a variable.
> 
> 
> 

If you can help and secondarily write out the significance of each line in layman's terms, that'd be of great help to me. 

Here is my first attempt:

```
def whilefunc(i):
    numbers = []
    for i in range(0,6):
        print "At the top i is %d" %i
        numbers.append(i)
        i += 1
        print "Numbers now: ", numbers
        print "At the bottom, i is %d" %i
    for num in numbers: 
        print num

```

Answer: 
The initial question above posed by black\_bird is [Study Drill 1 from Exercise 33](http://learnpythonthehardway.org/book/ex33.html) from Zed Shaw's [Learn Python the Hard Way](http://learnpythonthehardway.org/). 

In ex33 SD1, Shaw asks you to take his example while loop from the exercise and convert to a function replacing the hard-coded loop condition to a variable. While some of the answers above accomplish the goal, none follows the instructions outlined by Shaw which would require passing only one argument (the last answer above is close, but passes two). Below are two answers. The first is the best answer in accord with Shaw's Study Drill 1 from ex33 in line with what the reader has learned to that point. Only one argument is passed. The second gets user input instead of hard coding a number in the function call.

First answer:

```
def buildList(num):
    numList = []    
    i = 0       
    while i < num:
        numList.append(i)
        i += 1
        print "i: %d, " % i,
        print "list: ", numList
    #note: you don't need to return a value

#you can hard code any number here, of course
buildList(6)

```

Here is the second answer:

```
def buildList(num):
    #Convert num to int else infinite loop because num is a string
    num = int(num)  
    numList = []    
    i = 0       
    while i < num:
        numList.append(i)
        i += 1
        print "i: %d, " % i,
        print "list: ", numList

#getting/passing a string; converted to int within the function
answer = raw_input("Enter a number less than 10: ")
buildList(answer)

```
Think Zed Shaw just wanted us to convert the while loop (not the for loop) to a function... so I think it's just as simple as this.

```
def functiontocallforlist(x):
numList = []
i = 0
while i < x:
    print "At the top i is %d" % i
    numList.append(i)

    i += 1
    print "Numbers now: ", numList
    print "At the bottom i is %d" % i

#You can put whatever number you want as x really.
functiontocallforlist(8)

```