-3

I have the following code:

def do_math(a, b, kind = 'add' ):  

    if (kind=='add'):  
       return a+b  

    else:
       return a-b

do_math(1, 2)

I used this page, in order to convert ATOM into the interactive mode:

https://github.com/foreshadow/atom-python-run/wiki/12-How-Do-I-Use-atom-python-run#interactive-mode

But it returns 1, not 3 as expected.

Here is a screenshot:

Atom View, look at the returned value at the bottom...

How should I handle/solve this problem, so the returned value will be 3?


idleberg
  • 12,634
  • 7
  • 43
  • 70
Yoel Zajac
  • 453
  • 1
  • 6
  • 11
  • Assuming your code posted, it works for me (python 3.7 IDLE). Now, the link you posted, looks like you want to give arguments to the program and then use it on the code, that's complety another thing that has nothing to do with functions parameters. – lucas_7_94 Nov 04 '18 at 20:29
  • how is it not returning '3' ?! – dejanmarich Nov 04 '18 at 20:30
  • @lucas_7_94 I just want to drop any piece of code, and check it immediately, without adding modules, libraries etc. At least for this simple script, I expected it to work... :-( – Yoel Zajac Nov 04 '18 at 20:55

1 Answers1

1

I don’t use Atom but I’m going to infer that when it says file:1at the bottom there it’s actually referring to the first line of the file. The tick means that the code probably compiles.

You need to add a print() around your Function call so that the result can be printed to the console.

TerryA
  • 58,805
  • 11
  • 114
  • 143
  • @YoelZajac You're not looking at the console output, you're looking at something which tells you the line number – TerryA Nov 04 '18 at 20:55
  • I've solved the problem! Just debugged it line by line, and the answer 3 appeared in the box of the debugger. Thank you so much guys! Take care! Yoel. – Yoel Zajac Nov 04 '18 at 21:01