Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'tkinter': 0.07; 'separately': 0.09; 'toolkit': 0.09; 'useless': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'gui': 0.12; "computer's": 0.16; 'easier.': 0.16; 'exponent': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'notation': 0.16; 'notation,': 0.16; 'notations': 0.16; 'outputs': 0.16; 'pygtk,': 0.16; 'somehow,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'basically': 0.19; 'input': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'keyboard': 0.24; 'mathematical': 0.24; 'parse': 0.24; 'unicode': 0.24; 'math': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'primarily': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'easier': 0.31; 'constant': 0.31; 'gary': 0.31; 'critical': 0.32; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'similar': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'highest': 0.39; 'support,': 0.39; 'sure': 0.39; 'either': 0.39; 'users': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'simple': 0.61; "you're": 0.61; 'term': 0.63; 'provide': 0.64; 'between': 0.67; 'prompt': 0.68; 'asterisk': 0.84; 'black,': 0.84; 'hard.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=z76Krv1/nClwkR195GOpPAWG+zyUGcXvdS0YOWEbPFM=; b=m7NZUwx7/HBMpUduVzPraIqA7ES+DvRyB/WVwT/708BQFCQv0QqpGsqQv7+yubSwpt +RMFt+/h1NoOh67E+HERB/JsoVEXZv218cc90Wt+dLYw8rvnvsLce7YaxjkTpA47MgI5 NXY8TsvOGDecEtqrK89sBvRMAsLGKlzmRK8Yz0S1qQcf2OQk/Ldi5sekkDraAJmodUY4 2ZDlVdMOsDFgQ+l+lSQy1nDh362KIL7ZuY2lEHqMRuMmxCJDyW6qTBov4107H++z/liv hs8YRQIH/QEJM2Jhdbek6d1R5RLRqqk67VKrmg0y/6dQC8lFkV1dQt+NzrGptvvDVxgZ LegA== MIME-Version: 1.0 X-Received: by 10.43.94.7 with SMTP id bw7mr59079455icc.26.1412122850865; Tue, 30 Sep 2014 17:20:50 -0700 (PDT) In-Reply-To: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> References: <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> Date: Wed, 1 Oct 2014 10:20:50 +1000 Subject: Re: how to parse standard algebraic notation From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412122860 news.xs4all.nl 2829 [2001:888:2000:d::a6]:58583 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78518 On Wed, Oct 1, 2014 at 6:53 AM, math math wrote: > I want to basically write a program that inputs a polynomial in standard = algebraic notation and outputs its derivative. > > I know that I need to get the exponent somehow, but I am not sure how to = accomplish this in python (3.3) As Gary says, the form of input is really the critical part. How will users type these? One simple cheat you could do would be to prompt for each term separately - something like this: exponent =3D int(input("What is the highest exponent used? ")) terms =3D [] while exponent: terms.append(input("Enter coefficient of x^%d: " % exponent)) exponent -=3D 1 terms.append(input("Enter constant term: ")) You could do something similar with a GUI toolkit like tkinter or pygtk, too; provide input fields for the coefficients, and labels in between that say "x=C2=B2 + " etc. Otherwise, you're going to be primarily bound by the keyboard - your program is useless if it takes longer to key data into it than to do the work manually. Python 3.3 has excellent Unicode support, and Unicode has excellent support for mathematical notations, so you should be able to produce nice-looking output; but mathematical notation is much easier to write on a blackboard than on a computer's keyboard. (And even though some keyboards are black, like the one I'm using right now, it doesn't make it any easier. Sorry.) Gary's suggestions of the double asterisk and caret are two commonly-used notations for exponentiation in computers, so either would make some sense. Otherwise, you could come up with some other notation, but mainly, it has to be typeable. But hey! Once you have something you can type unambiguously, we can help you parse that into something you can make use of! That part's not too hard. ChrisA