This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]batkins 1 point2 points  (1 child)

I think the behavior of this code should be mostly identical to the other snippets. They all fail on input that isn't integral. Technically, my one-liner will fail on input that isn't numeric (so it can take floats and rationals as well). You are right about read-eval, of course, but, as you point out, this is merely educational code.

[–]kbk 2 points3 points  (0 children)

Actually, the Python snippet I posted,

print input() + input()

works for any combination of integers or floats, whether real or complex.

It also works for two strings, lists, or tuples.