Python Forum
Beginner Problem python 2.7 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Beginner Problem python 2.7 (/thread-11352.html)



Beginner Problem python 2.7 - Jonathan_levy - Jul-04-2018

i am using pycharm the lastest version and inteprter python 2.7
def sum_two_or_more(x1, x2, *args):
    if args:
        second = sum_two_or_more(x2, *args)
    else:
        second = x2
        return x1 + second
sum_two_or_more(1, 2)
i tried to run it and what printed out was:
Process finished with exit code 0

with nothing else and it did it to me with some others code like it doesnt have a problem or an error with the code i did but it didnt do what the code meant to do either


RE: Beginner Problem python 2.7 - gontajones - Jul-04-2018

If you want to see something in console, you have to use print().

def sum_two_or_more(x1, x2, *args):
    if args:
        second = sum_two_or_more(x2, *args)
    else:
        second = x2
    return x1 + second # Pay attention to the indentation

print sum_two_or_more(1, 2)

print(sum_two_or_more(1, 2)) # <- Python3
I recommend you to use/learn python3.


RE: Beginner Problem python 2.7 - ichabod801 - Jul-04-2018

One, you want to unindent the return statement. It's not a problem here, but if you give it three values, it will return None.

Two, try printing the result. As in:

print(sum_two_or_more(1, 2))
Three, upgrade to Python 3.6. Support for 2.7 is ending in a couple years.