The questions are in the comments of the code:

define f(x) {
print x^2
}
define g(x) {
print x+2
}
if(f(2)>g(1)) {
print "it works"
}
43         # Why 43 instead of the text "it works"?

a=f(2)
b=g(1)

if(a>b) {
print "it works"
}          
          # Why nothing?
有帮助吗?

解决方案

Your function merely print what they calculate. They don't return the result.

Thus when you call f(2), f will print 4 and when you call g(1), g will print 3.

Try it this way:

define f(x) {
    return x^2
}
define g(x) {
    return x+2
}
if(f(2)>g(1)) {
    print "it works"
}


a=f(2)
b=g(1)

if(a>b) {
    print "it works"
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top