I am writing a program of calculator for adding, subtracting, multiply and dividing infinite number of values.
I have tried multiple ways like :
values = [int(values) for values in input("Enter values: ").split()]
But this return a list of values and we can perform direct addition of values of list using built-in function sum() but I think we can't perform direct subtraction, multiplication and divide on list. So, for subtraction, multiplication and divide I create following function:
def multi(firstValue, *otherValues):
result = firstValue
for i in otherValues:
result = result * i
print(result)
In this function it takes two arguments firstValue
as integer and otherValue
as tuple.
When I give fixed arguments like:
multi(1, 2, 3, 4, 5)
it gives correct answer but when I take inputs from user than I am not to able to give correct argument like I mention up:
values = [int(values) for values in input("Enter values: ").split()]
multi(values)
Please give me some solution or some suggestion for taking inputs in other way or changing the way of performing tasks in other way.