The following code should do. for a in range(1,10): for b in range(1,5): for c in range(1,5): for mc in range(50, 55): if mc ==(6*a)+(9*b)+(20*c): print "mc= ",mc,"a= ",a,"b= ",b,"c=",c regards, Sarma.
On Mon, Aug 29, 2016 at 3:34 PM, Alan Gauld via Tutor <tutor@python.org> wrote: > On 28/08/16 23:53, shahan khan wrote: >> >> I changed the code a bit and this is the result: >> for a in range(1,11): >> for b in range(1,6): >> for c in range(1,6): >> mc=(6*a)+(9*b)+(20*c) >> if mc==50: >> print 'For 50 McNuggets:''a=',a,'b=',b,'c=',c >> if mc==51: >> print 'Fpr 51 McNuggets:''a=',a,'b=',b,'c=',c >> if mc==52: >> print 'For 52 McNuggets:''a=',a,'b=',b,'c=',c >> if mc==53: >> print 'For 53 McNuggets:''a=',a,'b=',b,'c=',c >> if mc==54: >> print 'For 54 McNuggets:''a=',a,'b=',b,'c=',c >> if mc==55: >> print 'For 55 McNuggets:''a=',a,'b=',b,'c=',c >> Result: >> For 55 McNuggets:a= 1 b= 1 c= 2 >> For 53 McNuggets:a= 1 b= 3 c= 1 >> For 50 McNuggets:a= 2 b= 2 c= 1 >> For 53 McNuggets:a= 4 b= 1 c= 1 >> >> Two questions: >> 1) why is it printing backwards? > > > It is printing in the order it finds them based on your loop values. > So the first two have a=1, the 3rd has a=2 and the last a=4 > > But please post in plain text not HTML since otherwise your code > format gets messed up. > > Alan G > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor