Hi
I have a function which rand digit between a and b. it maybe 2,3 or more digits. I want to save these digits in a list and then use them in another part of my program. How can I do it?

def dela(x):
    sum=0
    while sum <x:
        b= random.randrange (1,x-sum+1)
        sum = sum+b
        print b,
    return sum

Something like this might do it:

import random

def dela(x):
    sum=0
    mylist = []
    while sum < x:
        b = random.randrange (1, x - sum + 1)
        mylist.append(b)
        sum = sum + b
        #print b,
    return sum, mylist

# test it ...
sum, mylist = dela(5)
print mylist  # eg. [2, 1, 1, 1]

Hi
thank you very much it was agood idea.

Be a part of the DaniWeb community

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