[Tutor] Need all values from while loop - only receiving one
alan.gauld at yahoo.co.uk
Tue Jul 3 03:42:20 EDT 2018
On 02/07/18 23:52, Daryl Heppner wrote:
> The two While Loops are the part I'm struggling with. The goal is to
> list each bill month number and date for each month in the term.
When you need multiple values you need to use a collection
type such as a list or tuple. Your problem is that you are using
single valued variables to collect data but as you go round the
loops (not just the while loops) you are throwing away the data
you have already collected so that when the loop ends you only
have the last set of values.
> this example, I'm trying to return 36 rows, listed from 1-36 instead
> of one row followed by 24 rows numbered 37 to 60.
Personally I'd create a dictionary per row and store those
dictionaries in a list. (You could use a class instead of a dictionary
but I'm guessing that might be too big a step for a beginner.)
I'd also put all the parsing code into a function so that you
pass it the raw xml and get back the row dictionary.
That should simplify the structure of your code significantly
and make it easier to see what's going on. It should also be
easier to test the function on its own with some sample xml.
If you need more help with that let us know.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor