subtraction = 0 def sub(*x): l2 =list(x) l2.sort(reverse=True) sortedValue = l2 for i in sortedValue: global subtraction subtraction-=i #first parameter should not change.but here the value becomes negative print("Subtraction of numbers{0} = ".format(sortedValue),subtraction) return subtraction SubtractionResult = sub(20,2,5)
Subtraction = 0 def sub(*x): l2 =list(x) l2.sort(reverse=True) sortedValue = l2 for i in sortedValue: global subtraction
Subtraction
subtraction
l2 = list(x)subtraction=l2[0] # start with the first numberl2 = l2[1:] # create a new list of the remaining numbersfor x in l2: # subtraction -= x # subtract each number from the first one
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)