Please identify the mistake

This is the place for queries that don't fit in any of the other categories.

Please identify the mistake

Postby Ketchupcatchup » Tue Nov 19, 2013 3:24 am

Hello all, I am a beginner. There is this tutorial assignment on learnpython.org
It has a test for functions section for which my answer was :

Code: Select all
# Modify this function to return a list of strings as defined above
def list_benefits():
    strin = ['More organized code','More readble code','Easier code reuse','Allowing the programmers to share and connect code together']
    return strin
# Modify this function to concatenate to each benefit - " is a benefit of functions!"
def build_sentence(benefit):
    return benefit+" is a benefit of functions!"


Is there something wrong with the syntax/indendation?
The error on the output page was:

Code: Select all
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError: Sorry: IndentationError: ('unexpected indent', ('prog.py', 4, 1, '\treturn strin\n'))


Please help. :!:
Last edited by Mekire on Tue Nov 19, 2013 3:46 am, edited 1 time in total.
Reason: First post lock.
Ketchupcatchup
 
Posts: 2
Joined: Tue Nov 19, 2013 3:15 am

Re: Please identify the mistake

Postby metulburr » Tue Nov 19, 2013 5:22 am

There is this tutorial assignment on learnpython.org

what section? I searched real quickly, but i dont see where exactly you are, and i don't feel like hunting down where it is at. Describe where you are in that interactive tutorial.

is this the only code? There is no indentation error in the code given.

File "<string>", line 1, in <module>

My first guess would be code above this code is a mix and match of tabs and spaces

you can also use the str.join(list) built-in function to join a list of strings together split by str.
Code: Select all
lister = ['More organized code','More readble code','Easier code reuse','Allowing the programmers to share and connect code together']
section = ' is a benefit of functions! '
stringer = section.join(lister) + section
print(stringer)
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1412
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Please identify the mistake

Postby Ketchupcatchup » Tue Nov 19, 2013 5:30 am

Here is the link to page - http://www.learnpython.org/Functions
Below is the complete code. But the latter half is pre-written, to test the code the user writes. I don't expect errors there.
Code: Select all
# Modify this function to return a list of strings as defined above
def list_benefits():
    strin = ['More organized code','More readble code','Easier code reuse','Allowing the programmers to share and connect code together']
   return strin
# Modify this function to concatenate to each benefit - " is a benefit of functions!"
def build_sentence(benefit):
    return benefit+" 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.
Ketchupcatchup
 
Posts: 2
Joined: Tue Nov 19, 2013 3:15 am

Re: Please identify the mistake

Postby micseydel » Tue Nov 19, 2013 5:47 am

Lines 3 and 4 of the code you posted need to be indented to the same level (and hint: they're not).
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1256
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests