[Tutor] BEGINNER - HELP!!!
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Nov 9 10:57:32 EST 2020
On 09/11/2020 14:46, Leonard Ujomu via Tutor wrote:
> Help please,
> I just started learning python and I need assistance with the below code:
> def rectangle_area(base,height): area_a = base*height print("The area is " + str(area_a))
> rectangle_area(5,6)
I don't know if the formatting above is an error from the email system,
I'm guessing so. (You should set your mail to plain text when posting
to programming lists like this one, otherwise the indentation tends
to get stripped!) In which case your code should look like:
def rectangle_area(base,height):
area_a = base*height
print("The area is " + str(area_a))
rectangle_area(5,6)
> I am getting the error below when I run it :
Error on line 7: print("The area is " + str(area_a)) ^Tab
Error: inconsistent use of tabs and spaces in indentation
Please always include the fiull error message starting with the word
Traceback...
It includes a lot of useful data if you know how to read it.
> I understand where the error is but I cannot seem to rectify it.
Then you know more than me! :-)
I suspect that one of the indented lines has a tab character
whereas the others are all spaces. Or it might be the other
way around. Python is very picky about indentation, it requires
it to be consistent in its use of either all spaces or all tabs,
but not a mixture. Most of us get round this by using a programmers
editor which inserts the spaces for us.
In the email all your code had spaces, but if you check your
original you will likely find a tab lurking in there somewhere.
Incidentally you don't need the str() call or addition in
this line:
print("The area is " + str(area_a))
since print does that for you. You could just write:
print("The area is", area_a)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list