python elementtree - getting average
Question: Using element tree in python, I want to get an average value.

Below is my data

    
    
    Order A has a quantity of 12,10,and 5.. total is 27
    Order B has a quantity of 9 and 40... total is 49
    Order C has a quantity of 10,35, and 15.. total is 60  
    

When you total them then divide by 3, I should be getting 45.33. But on my
code below, I'm getting 20. :( I'm extracting the above data from an XML file.
Can you please help me identify the problem on my code. Thank you.

    
    
    import xml.etree.ElementTree as ET
    root = ET.ElementTree(file="nwind_medium.xml")
    
    orders = root.findall("./orders")
    for order in orders:
        orderdetails = order.findall("./orderdetails")
        total = 0
        for detail in orderdetails:
            quantity = detail.findall("./quantity")
            total += float(quantity[0].text)
    numberOrders = len(orders)
    
    print "The average number of itmes in order is", round((total / numberOrders),2)
    

Here's the whole XML file (updated) \- - - Vins et alcools Chevalier VINET - -
72 Mozzarella di Giovanni 34.8 5 - 14 Formaggi Fortini s.r.l. - - 11 Queso
Cabrales 14 12 - 5 Cooperativa de Quesos 'Las Cabras' - - 42 Singaporean
Hokkien Fried Mee 9.8 10 - 20 Leka Trading - - Toms Spezialitaten TOMSP - - 14
Tofus 18.6 9 - 6 Mayumi's - - 51 Manjimup Dried Apples 42.4 40 - 24 G'day,
Mate - - Hanari Carnes HANAR - - 65 Louisiana Fiery Hot Pepper Sauce 16.8 15 -
2 New Orleans Cajun Delights - - 41 Jack's New England Clam Chowder 7.7 10 -
19 New England Seafood Cannery - - 51 Manjimup Dried Apples 42.4 35 - 24
G'day, Mate


Answer: You are resetting total on each iteration through an order. If you need total
of all orders move

    
    
    total = 0
    

before the outer loop.

