generate functionMon, 06 Mar 2023

enter a floating point number n. Output ten numbers the total sum of which is equal to n. In the ten numbers displayed, the numbers do not go in a row. The output ten digits have exactly twelve digits after the decimal point. the numbers are positive.

import random def f(n): k = 0 while k < 10: r = random.random() if r + sum(lst) > 1: continue lst.append(r) k += 1 return lst print(f(0.9))

Questions about programming?Chat with your personal AI assistant