I have a piece of python code which I am generating 3 random integers between 0 and 100:
list1=random.sample(0, 100),3)
if sum(list1)=20:
print(list1)
else:
pass #do nothing
I want:
- The sum of the three generated numbers to equate to 20 and if it doesn't equal 20 to then repeat the code again until it comes up with 3 numbers that do equal 20.
- To keep doing this repeat N number of times so it has generated multiple lists that add up to 20.
Can anybody help? My ideas so far are something to do with loop functions but don't know where to start.
Aucun commentaire:
Enregistrer un commentaire