[Tutor] python arthematics

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Mar 22 23:29:24 CET 2012

>i want to write a program that reads simple arithematic epressions and calculates the result.
>for example input "1*3+2" should generate "5'" as result

So what is stopping you?
Snark aside, this can get really complicated unless you make some well
defined rules. This becomes difficult especially when you think about
whether you want to support order of operations. Should “1+3*2” generate
“7” or “8”? Do you want to support longer expressions or just 2 operations?

Personally, if I were learning the language I would make it do 1 operation.
Then after that I could consider how to make it do more operations.
Turning it into a true arithmetic calculator might be a bit much to start with.


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120322/1fff7f84/attachment-0001.html>

More information about the Tutor mailing list