How to print a program's return in Python -


this question has answer here:

i new python.

i have simple program finds greatest common denominator (gcd) of 2 numbers. goes this

def gcd(a, b):  if == b:      return  else:      if > b:          return gcd(a-b, b)      else:          return gcd(a, b-a) 

this text in notepad document titled gcd.py on desktop. can see program doesn't print returns greatest common denominator.

i need print results doing following print(gcd(25,10)). don't know can put line results need. tried inputting windows command line doing python print(gcd(25,10)). doesn't work. neither print(gcd(25,10)) in python interpreter.

i think supposed put in python interpreter, interpreter has set correct directory of desktop (where gcd file found)but cant seem that. tried o.chdir , when print(cwd) prints correct directory still doesn't work.

this first time using python i'm little confused.

try this. need print out in same file or import another:

def gcd(a, b):   if == b:       return   else:       if > b:           return gcd(a-b, b)       else:           return gcd(a, b-a)  print(gcd(25,10)) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -