On Wed, Oct 26, 2011 at 11:10 AM, Keshav Kini <keshav.k...@gmail.com> wrote:
> Hi Chappman,
>
> Well, unless the simple formula also refers to total_prob itself, that seems
> like a pretty pointless for loop, no? The variable will continually get
> overwritten, and you will just end up with the value it was assigned in the
> last iteration of the loop, so unless that value referred to the previous
> value, it means that all the other iterations were pointless.
>
> Anyway, the Python syntax (which is a subset of Sage syntax) for your loop
> is approximately this:
>
> for i in range(5):
>     for j in range(i-1):
>         do_something()
>
> That's all. No "end" statements, or semicolons, or what-have-you :) Keep in
> mind that indices are zero-based in Python (like C), so the first element of
> a list L is L[0], and range(5) is the list [0,1,2,3,4]. By the way, this
> kind of question more properly belongs in the sage-support group, rather
> than the sage-devel group, which is more for discussing the development of
> Sage itself.

Also, if you have a function f(i,j) which returns the i,j value you
can create the whole array as a list of lists like this:

[[f(i,j) for j in range(i-1)] for j in range(5)]

John

PS This would be better asked on sage-support.


>
> -Keshav
>
> ----
> Join us in #sagemath on irc.freenode.net !
>
> --
> To post to this group, send an email to sage-devel@googlegroups.com
> To unsubscribe from this group, send an email to
> sage-devel+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to