Prev: passing environment variable path to open command
Next: pyjsglade: GTK-glade-like UI builder for pyjamas
From: yanhua on 11 Jun 2010 10:11 hi,all£¡ it's a simple question: input two integers A and B in a line,output A+B? this is my program: s = input() 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..
From: superpollo on 11 Jun 2010 10:19 yanhua ha scritto: > hi,all�� > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() this does not work > 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. >>> import operator >>> print reduce(operator.add, map(int, raw_input().split())) 124312 41242 165554 >>> bye
From: Martin P. Hellwig on 11 Jun 2010 10:23 On 06/11/10 15:19, superpollo wrote: > yanhua ha scritto: >> hi,all�� <cut> >> s = input() > > this does not work <nitpicking> Well it does if it is python 3 and not 2 as you are using :-)</nitpicking> <cut> -- mph
From: Simon Brunning on 11 Jun 2010 10:25 2010/6/11 yanhua <gasfans(a)163.com>: > hi,allï¼ > it's a simple question: > input two integers A and B in a line,output A+B? print sum(int(i) for i in raw_input("Please enter some integers: ").split()) -- Cheers, Simon B.
From: Alex Hall on 11 Jun 2010 10:25
On 6/11/10, yanhua <gasfans(a)163.com> wrote: > hi,allï¼ > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() > 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. Just a thought, but less code is not always better; more code and comments often help others, and even yourself if you return to a project after some time, understand what the code does and how it works. However, you could try this: t=input().split() print(str(int(t[0])+int(t[1]))) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap(a)gmail.com; http://www.facebook.com/mehgcap |