Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with a simple calcfunc.
#1
Hi, im new to the program and i'm trying to create a function can solves a string input.
For example, user input: "1-5".
My program:
PHP Code:
def subtraction(n):
    if 
n.find('-')>0:
        
an.split('-'1)
        return 
subtraction(b)-subtraction(a)
    else:
        return 
float(n
will return as wanted -4, however if i type for example:
"1-5-1"
my program would return -3.
my problem is that the last expression is calculated first, so from "1-5-1" i would get 1-(5-1) = -3, how do i fix this to make it correct?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)