question on input function

John O'Hagan research at johnohagan.com
Mon Jul 20 03:44:44 CEST 2009


On Mon, 20 Jul 2009, Richel Satumbaga wrote:
> I am just learning python then I encountered an certain point in terms of
> using the input function of python. the source code:
>                        eq = input("enter an equation:");
>                        print " the result is : ";
>
>
> the output seen in the command window:
>
> enter an equation:[m*x+b for m in (0,10,1),for x in (1,11,1), for b in
> (2,12,1)]
>
> Traceback (most recent call last):
>   File "C:/Python26/try", line 1, in <module>
>     eq = input("enter an equation:");
>   File "<string>", line 1
>     [m*x+b for m in (0,10,1),for x in (1,11,1), for b in (2,12,1)]
>                                ^
> SyntaxError: invalid syntax

[...]

It's the extra commas in your list comprehension.This should work:

[m*x+b for m in (0,10,1) for x in (1,11,1) for b in (2,12,1)]

HTH,

John




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090720/273f60b8/attachment.html>


More information about the Python-list mailing list