I get an interesting problem:
Let’s take such a function for example:
def SumNumbers(a,b,c,d,e,f):
try:
print("Marta: ",
a,"+",b,'+',c,'+',d,'+',e,'+',f,
'=',
a + b + c + d + e + f)
except TypeError:
print("Enter the values for the 6 parameters of the program")
How we can handling this error in this case:
SumNumbers(1,2,3)
and in this case:
SumNumbers(1,2,3,4,5,5,6,77,7,8,88,8,8,8,8)
Of course, I mean handling this bug in the function body 🙂
My attempt to intercept a TypeError is unfortunately invalid 🙁
>Solution :
Use *args:
def SumNumbers(*args):
if len(args) != 6:
print("Enter the values for the 6 parameters of the program")
return
print(f"Marta: {' + '.join(str(i) for i in args)} = {sum(args)}")