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 range of output numbers is strictly not less than 0.001 and not more than 1. The displayed ten digits have strictly twelve digits after the decimal point.

def example(n): if type(n) is not int and type(n) is not float: return "This is not a number" if n <= 0 or n > 1: return "The range of number is incorrect" sum = 0 for i in range(1, 11): num = round(random.uniform(0.001, 1), 12) sum += num print(num, end = " ") if sum == n: return else: return "The sum of numbers is not correct" example(0.1)

Questions about programming?Chat with your personal AI assistant