a +b ?

Mark Dickinson dickinsm at gmail.com
Mon Jun 14 08:01:36 EDT 2010


On Jun 13, 5:46 pm, exar... at twistedmatrix.com wrote:
> On 04:25 pm, wuwe... at gmail.com wrote:
>
>
>
> >Steven D'Aprano <st... at REMOVE-THIS-cybersource.com.au> wrote:
> >>No, I think your code is very simple. You can save a few lines by
> >>writing
> >>it like this:
>
> >>s = input('enter two numbers: ')
> >>t = s.split()
> >>print(int(t[0]) + int(t[1]))  # no need for temporary variables a and
> >>b
>
> >Not that we're playing a round of code golf here, but this is a
> >slightly nicer take on your version:
>
> >one, two = input('enter two numbers: ').split()
> >print(int(one) + int(two))
>
> >I like names over subscripts, but that's just me :)
>
> Fore!
>
>     print(sum(map(int, input('enter two numbers: ').split())))
>
> Jean-Paul

58 characters.  You could remove the space after 'int' to make it 57.
Here's an evil 56-character version...

print(eval(input('enter two numbers: ').replace(*' +')))

--
Mark



More information about the Python-list mailing list