Change this:
print(calculate(splitter(expression)))
to this:
print(calculate(* splitter(expression)))
The error is that calculate
expects three float values (x
, and y
, and z
), but splitter
returns a tuple object ((x, y, z)
as one object, similar to arrays in other languages):
>>> type(splitter("1 + 2"))
<class 'tuple'>
Prepending a tuple or a list with a *
operator (unpacking or splatting) unpacks the object into its individual items that are then passed to the function as separate arguments.
In fact, str.split()
already returns a tuple. By assigning multiple values at once in x, y, z = expression.split()
, you actually unpack the returned tuple into individual values, then in return x, y, z
, you pack those values into a tuple.