generate functionTue, 07 Mar 2023

a fractional number n is entered from the keyboard. Output ten numbers. The sum of all ten numbers displayed is n.

def func(n): a = 0 str_a = '' i = 1 while a < n: i += 1 if n - a - i > 1: a += i str_a += str(i) + ' + ' else: str_a += str(n - a) break return str_a print(func(18))

Questions about programming?Chat with your personal AI assistant