TypeError: 'NoneType' object is not iterable - Learning python, tad confused.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Barry1point4
    New Member
    • Jul 2012
    • 2

    TypeError: 'NoneType' object is not iterable - Learning python, tad confused.

    I've been learing python from http://www.learnpython.org/page/Functions and in the functions lesson I've got stuck on the exercise for 2 days now.

    As far as I can tell my code should work but when i run it, it returns TypeError: 'NoneType' object is not iterable. Can anyone explain why?

    My code is:
    Code:
    def list_benefits():
        print 'More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together'
    def build_sentence(info):
        return '%s' % list_benefits + ' is a benefit of functions'
    def name_the_benefits_of_functions():
        list_of_benefits = list_benefits()
        for benefit in list_of_benefits:
            print build_sentence(benefit)
    
    name_the_benefits_of_functions()
    Thanks Barry1.4
    Last edited by bvdet; Jul 19 '12, 06:31 PM. Reason: Add code tags
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    Function list_benefits prints a set of strings. What i assume you want it to do is return a list.
    So:
    return ['More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together']

    Comment

    • noobster6616
      New Member
      • Jul 2012
      • 2

      #3
      I think this is what you need to do to make it work . . .

      change line 2-3 in your code
      from
      print 'More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together'
      to
      return "More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"

      then line 5
      from
      return '%s' % list_benefits + ' is a benefit of functions!'
      to
      return info + " is a benefit of functions!"

      That should work

      Comment

      • Barry1point4
        New Member
        • Jul 2012
        • 2

        #4
        Thanks for both anwsers, they both worked well, and thanks to Smygis for helping me to understand.

        Comment

        Working...