0

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
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Mackjan
0

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)
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.