Jun-18-2019, 01:53 PM
Hi,
I have a calculator project, I am able to give 2 numbers and operator to get answer after pressing = sign. Example, 1+2=3. Now, what if the user keeps adding operators before pressing the = sign. Example, 1+2+3+4+5+6+7=answer. how to track them all? I have a function that will take the first operation 1+2 passing 2 variables and an operator. How can I deal with such problem if the list is long before pressing the = sign?
I have a calculator project, I am able to give 2 numbers and operator to get answer after pressing = sign. Example, 1+2=3. Now, what if the user keeps adding operators before pressing the = sign. Example, 1+2+3+4+5+6+7=answer. how to track them all? I have a function that will take the first operation 1+2 passing 2 variables and an operator. How can I deal with such problem if the list is long before pressing the = sign?
def math(val1,operator,val2): if operator = "+": return val1+val2 elif operator = "-": return val1-val2this is if the operation is taking 2 values, how to deal with this if it is more than that.