def arithmetic(num,type,num2) result=0 if type.eql?("+") num+num2=result; elsif type.eql?("-") num-num2=result; elsif type.eql?("*") num*num2=result; elsif type.eql?("/") num/num2=result; end return result; end result = arithmetic(4,"+",8) puts result;
[解决办法] def arithmetic(num,type,num2) result=0 if type.eql?("+") result = num+num2; elsif type.eql?("-") result = num-num2; elsif type.eql?("*") result = num*num2; elsif type.eql?("/") result = num/num2; end return result; end result = arithmetic(4,"+",8) puts result; [解决办法] num+num2=result; this line, what's your want? you want to assign result value to num2? Result value will be never changed in your code. [解决办法] 这不就是一楼的么……