a +b ?

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Fri Jun 11 11:31:58 EDT 2010


yanhua <gasfans at 163.com> writes:

> it's a simple question:
> input two integers A and B in a line,output A+B?
>
> this is my program:
> s = input()

input() is probably not what you think it is. Check raw_input instead.

> t = s.split()
> a = int(t[0])
> b = int(t[1])
> print(a+b)
>
> but i think it's too complex,can anybody tell to slove it with less code.

print sum(map(int,raw_input().split()))

or replace sum by reduce. BTW, it works with any number of integers

You can find this by walking backwards in your code, starting at a+b,
and generalizing a little bit on your way.

-- Alain.



More information about the Python-list mailing list