http://ideone.com/PgjrII
forが終わったあとにprint(sum)すればいい