python - Is there a way to add multiple conditions in a for loop? -
n=int(raw_input('enter number of mcnuggets want buy : ')) #total number of mcnuggets want yo buy in range(1,n) , b in range(1,n) , c in range(1,n) : if (6*a+9*b+20*c==n): print 'number of packs of 6 ',a print 'number of packs of 9 ',b print 'number of packs of 20 are',c
i new programming , learning python.the code above gives errors. suggestion.?.
you should use nested loops:
for in range(1, n): b in range(1, n): c in range(1, n): if ...
or better:
import itertools a, b, c in itertools.product(range(1, n + 1), repeat=3): if ...
Comments
Post a Comment