[Tutor] print label error

Dave Angel davea at davea.name
Tue Mar 5 02:00:57 CET 2013


On 03/04/2013 07:28 PM, Pravya Reddy wrote:
> Hi
>    I am having a builtin intendation error for print Addem(3,2).Does it vary
> for different versions of python?
>   How to clear the error?
>
>
> def Addem(this, that):
>      return this + that
>   print Addem(3, 2)

The print statement doesn't line up with the return statement, and it 
doesn't line up with the def statement.  Those are the only two valid 
indentations.  I expect you intended these lines to begin at the left 
margin, and the two spaces are going to be a problem.

This is true for every version of Python.  However, there is one 
difference about indentation that I know of:  starting in version 3, 
mixing tabs and spaces is an explicit error instead of just a really 
stupid idea.

>   print Addem("book", "worm")
>   print Addem(3.2, 1)
>   try:
>          print Addem("caution",1)
>   except TypeError:
>          print('typeerror raised for Addem("caution", 1))
>   try:
>          print Addem(14)
>   except TypeError:
>          print('typeerror raised for Addem(14)')
>      print Addem
>      print("Addems done.")
> def PrintSum(this, that):
>      print(this + that)
> print(printsum('high', 'heel')
>      def DoSomething(data):
>          for index,datum in enumerate(data):
>              print(datum,)
>              if index % 3 == 2:
>                  print
>              print
>          a_string = "earthshine"
>          a_list = [1,2,3,4,5,6,7]
>      DoSomething(a_string)
>      DoSomething(a_list)
>
>

Next time, please include the actual error message, which was probably 
about 4 lines long.  It would make things much easier.


-- 
DaveA


More information about the Tutor mailing list