I am completely new to Python.
I have a simple Program that finds the greatest common denominator (GCD) of two numbers. It goes like this
def gcd(a, b):
if a == b:
return a
else:
if a > b:
return gcd(a-b, b)
else:
return gcd(a, b-a)
This text is currently in a notepad document titled gcd.py
on my desktop. As you can see the program doesn't actually print anything it just returns the greatest common denominator.
I need to actually print the results by doing the following print(gcd(25,10))
. I don't know where I can put that line to get the results I need. I tried inputting it into the windows command line by doing python print(gcd(25,10))
. But that doesn't work. Neither does print(gcd(25,10))
in the python interpreter.
I think I am supposed to put it in the python interpreter, but that the interpreter has to be set to the correct directory of my desktop (where the gcd file is found)but I cant seem to do that. I tried o.chdir
and when I print(cwd)
it prints the correct directory but it still doesn't work.
This is my first time using python so I'm a little confused.