Hi
I have an idea to rand some digit which sum is equal to my inputs digit. If I put in 12 then I like to have 4, 2, 6 or 4,4, 4 or 3, 3, 3, 3 …….etc. Not more and not lease then my input.
In my function X= a digit from 1 to 52.

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

You almost have it.
Change

while sum <=x:
    b= random.randrange (1,x-1)

to

while sum <x:  # Not <=
    b= random.randrange (1,x-sum+1)

You almost have it.
Change

while sum <=x:
    b= random.randrange (1,x-1)

to

while sum <x:  # Not <=
    b= random.randrange (1,x-sum+1)

Hi
Than you very much it was a very good 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.