[Tutor] my first project: a multiplication trainer

Simone simozack at yahoo.it
Mon Mar 17 17:15:48 CET 2008

Guba ha scritto:

> I was unable to find information on tuple(). (The Python help function
> was rather conservative in its output, Google not helpful).
> What exactly is the use of tuple(q) here, and why does not a simple q
> instead of tuple(q) do? The latter would have been my intuitive
> expectation...

The print statement "%dx%d = " needs a tuple of arguments. The tuple() 
command, that converts a list or a set of values in a tuple of values, 
prevent that error (for example, if the list of values is a list o of 
list, the print statemnte returns the error "TypeError: in argument 

For example:

 >>>a = [[1, 2], [3, 4]] # a is a list of lists with 2 values

<type 'list'>

<type 'tuple'>


 >>>a = [(1, 2), (3, 4)] # a is a list of tuples with 2 values

<type 'tuple'>

> The other thing I have on my mind is this: how could I have the program
> ask the math questions not horizontally but vertically? An example:
>  4
> x7
> =

Simply insert a \n in the print statement, like this:

print "%d\nx%d\n = "

Chiacchiera con i tuoi amici in tempo reale! 

More information about the Tutor mailing list