11-16-2009, 04:12 PM
That cant be efficent lol
This may help you a bit, I threw it together real quick
This may help you a bit, I threw it together real quick
Code:
#!/usr/bin/env python
class Calculations( object ):
def Addition( self, Numbers ):
return sum( Numbers )
def Subtract( self, Numbers ):
Total = Numbers[ 0 ]
for Index, Num in enumerate( Numbers ):
try: Total -= Numbers[ Index + 1 ]
except IndexError: return Total
def Multiply( self, Numbers ):
Total = 1.0
for Num in Numbers: Total *= Num
return Total
def Divide( self, Numbers ):
Total = Numbers[ 0 ]
for Index, Num in enumerate( Numbers ):
try: Total /= Numbers[ Index + 1 ]
except IndexError: return Total
Numbers, Counter, Answer = [], 0, True
while Answer:
Counter += 1
try:
Answer = int( raw_input( "Number %i: " % ( Counter ) ) )
Numbers.append( Answer )
except ValueError: Answer = False
if len( Numbers ) < 2: print "Error: You need atleast two numbers..."
else:
Methods, Method = ["add", "subtract", "divide", "multiply"], False
while not Method in Methods: Method = raw_input( "Add/Subtract/Divide/Multiply? : ").lower()
Math = Calculations( )
if Method == Methods[ 0 ]: print Math.Addition( Numbers )
if Method == Methods[ 1 ]: print Math.Subtract( Numbers )
if Method == Methods[ 2 ]: print Math.Divide( Numbers )
if Method == Methods[ 3 ]: print Math.Multiply( Numbers )
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation