I'm doing a project where I have a list of number random numbers get choosen from it:
list = [1,2,3,4,5,6,7,8,9]
for i in range(5):
first = int(random.choice(list))
second = int(random.choice(list))
third = int(random.choice(list))
sumofall = (first + second + third)
And It sums the random numbers and gives a result as 'int' and I have str that gives which numbers summed to get that result like:
which_num = str(first) + ' + ' + str(second) + ' + ' + str(third) #Equals 7
As it showen in the 1st code i want to find its result and which numbers are summed to find it and from the results like: 9, 12, 8. I want to find the which of the result is the closest to this int and also show which numbers are summed to get that result
Want result like
list of summed numbers: 9, 12 ,8, 10, 13
I want the number closest to 14
It prints/shows:
Closest one is: 13
Summed these: 2 + 5 + 6
Maybe it can be solved easier with pandas but I'm not sure