[Tutor] Python and Tuples

Alan Gauld alan.gauld at btinternet.com
Sun Jan 30 15:28:14 CET 2011


"Becky Mcquilling" <ladymcse2000 at gmail.com> wrote

> I'm fairly new to python and I am trying to do some math with 
> tuples.
>
> If I have a tuple:
>
> t =( (1000, 2000), (2, 4), (25, 2))

Thats a tuple of tuples. The pairs of numbers each make up a tuple.
And the triple of pairs makes up another tuple.

> I want to loop through and print out the results of the multiplying 
> the two
> numbers like so:
>
> 1000 x 2000
> 2 x 4
>
> etc.
>
> I'm not sure of the syntax for that.  Any ideas?

Which bit are you not clear about?
How to extract the pairs of numbers?
Or how to access the individual numbers in the pair?
Or how to do the math?
Or how to print the result?

Its always good to show us what you have tried so that
we can see where you are struggling.

HTH


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list