generate functionMon, 06 Mar 2023

enter a floating point number n. Output ten numbers whose sum is equal to n. In the ten numbers displayed, the numbers do not go in a row. The range of output numbers is from 0.001 to 1. The output ten digits have exactly twelve digits after the decimal point. The output numbers are strictly greater than 0.

import random import math import decimal def get_nums(n): nums = [] remain = n for i in range(10): if remain <= 0: num = 0 elif i == 9: num = remain else: num = round(remain * random.random(), 12) nums.append(num) remain = remain - num return nums get_nums(1.23)

Questions about programming?Chat with your personal AI assistant