> assert create_table(5, 3) == [(0, 1, 2), (3, 4)] > AssertionError > > I know that my method of calculating the number of rows is faulty, > but I'm not sure how to correct it.
num_rows = (num_items/row_size) + (num_items%row_size) This uses integer division then adds the remainder, so for your example of 5,3 we get 5/3 = 1 5%3 = 2 So rows = 3 - wrong! All you want to do is add one if the modulus is not zero, so num_rows = (num_items/row_size) if num_items % row_size > 0: num_rows += 1 Should do what you want. HTH, Alan G.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor