X-Received: by 10.224.5.5 with SMTP id 5mr3972304qat.4.1380710664815; Wed, 02 Oct 2013 03:44:24 -0700 (PDT) X-Received: by 10.50.9.33 with SMTP id w1mr60784iga.12.1380710664673; Wed, 02 Oct 2013 03:44:24 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!q9no1003259qas.0!news-out.google.com!9ni1076qaf.0!nntp.google.com!q9no1003256qas.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Wed, 2 Oct 2013 03:44:24 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.174.172.16; posting-account=RUehzwoAAACZg4O9HgjN-xsBnq574C5_ NNTP-Posting-Host: 122.174.172.16 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <77bde84a-b0ce-4061-bb2e-e6cd23f4282c@googlegroups.com> Subject: Efficency help for a Calculator Program From: JonDoe297 Injection-Date: Wed, 02 Oct 2013 10:44:24 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:55303 You may remember me from this : https://groups.google.com/forum/#!topic/comp.lang.python/PIkUno3avkw I need help to increase the efficiency of this code : global repeat repeat=1 def main(): c=int(raw_input("How many numbers do you want to work? (Min. 2 Max. 3) ")) if c==2: x=int(raw_input("Enter the first number to be worked ")) y=int(raw_input("Enter the second number to be worked ")) elif c==3: x=int(raw_input("Enter the first number to be worked ")) y=int(raw_input("Enter the second number to be worked ")) z=int(raw_input("Enter the third number to be worked ")) else: print "Invalid input.";raw_input("Press to close this window");exit() p=int(raw_input("Do you want to divide, subtract, add or multiply these numbers? (1=divide, 2=subtract, 3=add, 4=multiply) ")) if p==1 and c==2: print "The result is : ",x/y repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==1 and c==3: print "The result is : ",x/y/z repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==2 and c==2: print "The result is : ",x-y repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==2 and c==3: print "The result is : ",x-y-z repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==3 and c==2: print "The result is : ",x+y repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==3 and c==3: print "The result is : ",x+y+z repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==4 and c==2: print "The result is : ",x*y repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() elif p==4 and c==3: print "The result is : "+str(x*y*z) repeat=int(raw_input("Do you want to calculate for more numbers? Yes=1 No=2 ")) if repeat==1: main() else: repeat=int(raw_input("Invalid Input. Please read instructions properly. Would you like to try again? Yes=1 No=2 ")) if repeat==1: main() else: exit() main() Is there any way to make it smaller? It does it's job, but I want it to look smaller, more efficient.