generate functionTue, 07 Mar 2023

a fractional number n is entered from the keyboard. Output ten numbers whose sum is equal to n. The numbers range from 0.001213245678 to n. The numbers are positive. The first two digits after the decimal point in the number can be equal to 0. The remaining digits in the number go without repetition. The number must have twelve significant decimal places.

# -*- coding: utf-8 -*- import itertools def func(n): n = round(n,8) n = str(n).split('.')[1] n = n[:4] lst = list(itertools.combinations(range(10), 4)) lst = [i[:2] for i in lst if i[2] == i[3] and i[0] != i[1] and i[0]!=0 and i[1]!=0] lst = [i[0]*10 + i[1] for i in lst] lst = [1.0*int(n[i:i+2])/100 for i in range(len(n)) if i % 2 == 0] s = sum(lst) lst = [0.01*i for i in lst] lst.append(n-s) return lst

Questions about programming?Chat with your personal AI assistant