News for hackers. Stuff that matters.
Re:How To Write A Calculator in 70 Python Lines by philfreo on Saturday February 23, 2013 @05:08PM (#5271705)
How to Write a Calculator in 1 Python Line

    print input()

    > 25*4-50
    > 50
Re:How To Write A Calculator in 70 Python Lines by erezsh on Saturday February 23, 2013 @07:48PM (#5272167)
Q. How to write code?

A. I don't need to; other people will write it for me.

That's fine, I guess. I prefer to understand.

Re:How To Write A Calculator in 70 Python Lines by pekk on Saturday February 23, 2013 @11:58PM (#5272918)
How to get things done? Use existing tools unless they are not suitable.
Re:How To Write A Calculator in 70 Python Lines by prezjordan on Saturday February 23, 2013 @05:26PM (#5271757)
...100? Your calculator seems broken :)
Re:How To Write A Calculator in 70 Python Lines by philfreo on Saturday February 23, 2013 @05:39PM (#5271794)
haha thanks, fixed
Re:How To Write A Calculator in 70 Python Lines by edwintorok on Saturday February 23, 2013 @05:21PM (#5271741)
It accepts more than just numbers though:

  >>> print input()
  "a"+"b"
  ab
Re:How To Write A Calculator in 70 Python Lines by adr_ on Saturday February 23, 2013 @08:05PM (#5272221)

  try:print(lambda x:eval(x)if all(i in'0123456789.*/+-'for i in x)else'syntax error')(raw_input())
  except:print'error'
Re:How To Write A Calculator in 70 Python Lines by readme on Saturday February 23, 2013 @09:00PM (#5272399)
Mathematically, this is wrong.. a + b is not ab.
Re:How To Write A Calculator in 70 Python Lines by xxbondsxx on Saturday February 23, 2013 @09:36PM (#5272498)
It's not symbolic...
Re:How To Write A Calculator in 70 Python Lines by readme on Saturday February 23, 2013 @09:52PM (#5272558)
Of course. I understand that "a" + "b" when taken to mean "concatenate the strings" is "ab" but OP's post was a calculator. It would not have yielded this result.
Re:How To Write A Calculator in 70 Python Lines by Hello71 on Saturday February 23, 2013 @06:10PM (#5271885)
it's a feature
Re:How To Write A Calculator in 70 Python Lines by gshubert17 on Saturday February 23, 2013 @10:20PM (#5272630)
Or, from a bash command line,

$ python -c "print input('> ')" > 2+3*5 17

Re:How To Write A Calculator in 70 Python Lines by waltz on Saturday February 23, 2013 @05:26PM (#5271759)
or just 'python'
Re:How To Write A Calculator in 70 Python Lines by BerislavLopac on Saturday February 23, 2013 @05:25PM (#5271752)
The. Best. Comment. Ever. :-)