I am trying to create a calculator, but I am having trouble writing a function that will subtract numbers from a list.
For example:
class Calculator(object):
def __init__(self, args):
self.args = args
def subtract_numbers(self, *args):
return ***here is where I need the subtraction function to be****
For addition, I can simply use return sum(args)
to calculate the total but I am unsure of what I can do for subtractions.
subtract
" function? For sum, it's intuitive. You just add all the numbers. But for subtraction, what are you subtracting from and what are you subtracting? – Orleanistfirst_element - sum(rest_of_elements)
? Is itsum(args[i] * (-1)^1
? is itabs(max(list) - sum(rest_of_elements))
? As you can see, there are endless number of possibilities - what exactly are you after? – Clip