# Shortest python A + B program with input and output

Some of you may say that I am wasting my time, but this task does not give me peace for more than 500 days. It is required to write a program in Python 3.x that takes two numbers as input and displays their sum. The numbers are given in the following format:

a b


Some example test cases:

100 500 -> 600
3 4     -> 7


The length of the code is calculated with the formula max(code length without spaces or tabs or newlines, code length / 4). I know only 2 solutions, each of them has a length of 36 characters:

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


and:

print(eval(input().replace(' ', '+')))


Also I know, that the exists solution with length of 34 symbols. You can check it on this website.

• If spaces don't count, I have a 34-char solution (SHA1 is e3eb1f896cffc2dbff531ce5ba8fa25d34c22c76). I'm not sure though it would be good to publicly post a solution to what seems to be a continuing programming competition. Do we have a site policy on that? – xnor Apr 17 '17 at 10:34
• @ xnor, it's very old task, nobody can stop you to solve this problem here. – Evgeny Apr 17 '17 at 10:43
• @xnor as we already got an 34-char solution, would you mind posting yours? Claudio's SHA1 is different than yours – Felipe Nardi Batista Apr 18 '17 at 11:04
• @FelipeNardiBatista It's the same thing with double quotes. – xnor Apr 18 '17 at 21:55

Given the right hint toward the solution in the comment to the same question asked on stackoverflow ( see here ), I have got it right down to 34 and without any limitations on the input number or other tricks necessary:

print(eval(input().replace(*' +')))

Here a short summary of currently known different solutions:

print(eval(input().replace(' ','+'))) # 36

print(sum(map(int,input().split()))) # 36

print(eval(input().replace(*' +'))) # 34

print(sum(map(int,input()[::2]))) # 33 (limited to numbers between 0 and 9)

Maybe it could be considered cheating, but maybe not. At least there is no rule for this defined yet so let's include it into the collection of possible solutions:

import f;f.f() # 13

Required for this solution to work is a script f.py available in a search directory for modules of Python with following content:

def f():
print(sum(map(int,input().split())))

• If you read the question, it has to work on the given website, where there would not be an external script to import. – mbomb007 Apr 17 '17 at 20:35
• @mbomb007 : I have read the question and it is not mentioned in the question, or can you provide a citation from the question stating that it is? – Claudio Apr 17 '17 at 20:41
• "You can check it [(the problem)] on this website." And on the website, the specifications require input from STDIN. acmp.ru/index.asp?main=task&id_task=1 You don't get to create another module. – mbomb007 Apr 17 '17 at 20:43
• @Claudio thank for the answer. The correct version is print(eval(input().replace(*' +'))) # 34 – Evgeny Apr 17 '17 at 22:29
• @Claudio, can I close duplicate of this question on stackoverflow? – Evgeny Apr 18 '17 at 9:03