[Tutor] More Advanced Calculator.

. Sm0kin'_Bull administrata at hotmail.com
Mon Feb 21 21:55:26 CET 2005

With your helps i managed to program Advanced Calculator.
But, I want to change(or add) some to it.

1. How can i /n/n result bit? I tired.. but, I can't

2. How can i enable it to calculate float-pointing numbers? (Which will make 
it complicated)

It should looks like this...

Please input data

Mathsmetical Sign:


And the source i got

import operator

ops_dict = {'+': operator.add, '*' : operator.mul, '-' : operator.sub,
            '/' : operator.div}

def perform_arithmetic():
     print "Please input data"
     number1 = int(raw_input("\nNumber1: "))
     sign = raw_input("Mathsmetics Sign: ")
     number2 = int(raw_input("Number2: "))

         result = ops_dict[sign](number1, number2)
     except KeyError:
         raise NotImplementedError, "I don't know the sign '%s'" %sign

     # add output formatting logic as desired

     return result

print perform_arithmetic()


Cheers! :)

Express yourself instantly with MSN Messenger! Download today it's FREE! 

More information about the Tutor mailing list