[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

Number1:
Mathsmetical Sign:
Number2:


Result:


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: "))

     try:
         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()

raw_input("")


Cheers! :)

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Tutor mailing list