Python 2 vs Python 3


Can you tell me what’s wrong with my code ? Did I do something weird to a “programmer’s” eyes?
My code works perfectly on python 3 but not on the codecademy(which I was told that they still use python 2).
Thank you so much! :blush: :smile:

def digit_sum(n):
    dismantled = []
    for num in n:
    print (sum(dismantled))

digit_sum(input("Enter number: "))


in pyton2, input() will be evaluated as code. use raw_input in python2


Hi @l337_wolfsrain,

Whether you run your program in Python 2 or Python 3, the digit_sum function should return its result rather than print it, if it is to conform to Codecademy’s instructions. Without a return statement, it will return the value None.

For Python 2, it is best to use raw_input rather than input to obtain user input.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.