Q:

Appending result of function into a list

I'm calling a function within a function. I want it so that every time the function loops (4 instances) it adds the result to a list. In bad programmer terms, something like: for each instance of the loop, run function, add result to list and increment counter, and go again.
Can you help here?
def genDigit():
    import random
    digit = (random.randint(0, 9))
    print(digit)
    return

def genNumber():
    numList = list
    for counter in range(0,4):
    'from here on I need to finish the function

Any pointers would be greatly appreciated. I understand in english terms how I would go about finishing this.
Kind regards, 
JJP

A:

Instead of printing the digit in your function and then returning nothing, you should return the generated digit. You can then collect those in a list, and return that list. Finally, you print the result.
import random # import once

def genDigit():
    digit = random.randint(0, 9)
    return digit # return the digit

def genNumber():
    numList = list() # add missing ()
    for counter in range(0,4):
        numList.append(genDigit()) # add digits to list
    return numList # return the list

print(genNumber()) # now print the entire list

Or shorter:
def genDigit():
    return random.randint(0, 9)

def genNumber():
    return [genDigit() for c in range(4)]

