Excellent all working good, thank you. Regards, Jag BraveArt Multimedia
On Saturday, 2 May 2015, 22:28, Dave Angel <d...@davea.name> wrote: On 05/02/2015 04:36 AM, Peter Otten wrote: > Jag Sherrington wrote: > With that the calculation becomes > >>>> buns = 20 >>>> package_size = 8 >>>> whole_packages, missing_buns = divmod(buns, package_size) >>>> total_packages = whole_packages >>>> if missing_buns: total_packages += 1 > ... >>>> total_packages > 3 > And that can be simplified: buns = 20 package_size = 8 total_packages = (buns + package_size - 1) // package_size #desired answer 3 Or, to take better advantage of the Python library: import math total_packages = math.ceil(buns/package_size) This is exactly what the ceiling and floor mathematical concepts are needed for. Note, I'm using the fact that the OP is writing in Python 3. If not, one should probably add from __future__ import division . -- DaveA _______________________________________________ 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