Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55307

Re: Efficency help for a Calculator Program

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.050
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'output': 0.05; 'level,': 0.07; 'subject:help': 0.08; 'main()': 0.09; 'declaration': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'inputs': 0.16; 'loop.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'error': 0.23; 'skip': 0.24; 'header :In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'quite': 0.32; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'doing': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'hope': 0.61; 'matter': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'more': 0.64; 'different': 0.65; 'bottom': 0.67; 'anything.': 0.68; 'clearer': 0.84; 'more?': 0.84; '2013': 0.98
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:to :content-type; bh=mwbdiLMO5fFlhWIlDSNIiJM7UaR+rtY/RjGklI396Z0=; b=no9+GyksF2Ed1fqyiThcyLfMPZe31fDbwv0ooLab8Hi5Cn1fEtP8cTj/CVXEfPKVC4 6OIiF6rPlKqfEVQb6TWey4Jxy6xXJAgo9Af0C29mfdOCRzWzGRNL/betC5tYOwwptXMU qf8EQSkedt+68llSQMLXPeZYhujPGSXZoaovjV6NGIElsxlbZvRteJe2XgOU2p1HavFo Z1r/s9EOBRjKWUqHlrWzExxfjeTyS0hUAIa4hsKkgMX9wTsbwl82izmBY09sVyumt6Wd TsVtycuZ0fti5L4wvTRrEk3N6rc3m/W39NUU+pUH1C0cVyKW9Ptkr87PM2SYsSwRtFWW Mw8w==
MIME-Version 1.0
X-Received by 10.68.192.195 with SMTP id hi3mr1891743pbc.18.1380711663536; Wed, 02 Oct 2013 04:01:03 -0700 (PDT)
In-Reply-To <77bde84a-b0ce-4061-bb2e-e6cd23f4282c@googlegroups.com>
References <77bde84a-b0ce-4061-bb2e-e6cd23f4282c@googlegroups.com>
Date Wed, 2 Oct 2013 21:01:03 +1000
Subject Re: Efficency help for a Calculator Program
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.611.1380711666.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380711666 news.xs4all.nl 15897 [2001:888:2000:d::a6]:39243
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:55307

Show key headers only | View raw


On Wed, Oct 2, 2013 at 8:44 PM, JonDoe297 <vignesh.harikrishna@gmail.com> wrote:
> Is there any way to make it smaller? It does it's job, but I want it to look smaller, more efficient.

Yes, it is, but let me first clarify something: "Smaller" and "more
efficient" are two quite different concepts. Efficiency doesn't matter
to your code here, so what you're looking for is smaller, clearer
code. Which is a good thing to be doing :)

At top level, the 'global' declaration doesn't do anything. You may as
well not bother with it.

If you change your recursive main() function into a while loop, you'll
be able to combine all your common code very easily. I won't do the
whole job for you, but consider this structure:

repeat=1
while repeat==1:
    # get inputs
    # calculate and produce output
    repeat=int(raw_input("Do you want to do more? "))

And if you need your error state to have a different prompt, you can
use 'continue' to skip the bottom of the loop.

Hope that helps!

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Efficency help for a Calculator Program JonDoe297 <vignesh.harikrishna@gmail.com> - 2013-10-02 03:44 -0700
  Re: Efficency help for a Calculator Program Chris Angelico <rosuav@gmail.com> - 2013-10-02 21:01 +1000
    Re: Efficency help for a Calculator Program JonDoe297 <vignesh.harikrishna@gmail.com> - 2013-10-02 06:43 -0700
  Re: Efficency help for a Calculator Program Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-02 19:47 -0400
  Re: Efficency help for a Calculator Program Chris Angelico <rosuav@gmail.com> - 2013-10-03 10:25 +1000
  Re: Efficency help for a Calculator Program Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-03 19:15 -0400
  Re: Efficency help for a Calculator Program Chris Angelico <rosuav@gmail.com> - 2013-10-04 16:45 +1000

csiph-web