You have an indentation problem. The subsequent code after the body of the function should be on the first level of indentation(def level). Also, it seems your function is calculating area but not returning or printing the calculated value.Use a return(or print) statement within the function to return/print the calculated area(a). Modify your code as follows:
def area(l,b):
***a = l * b
***print("Area is: ",a)
area(4,6)
area(5,8)
area(2,100)
I hope this helps!
Consider the *** as spaces. The editor did not render the indented function body properly when i used spaces to indent so I used the asterisks as placeholders to make it clearer.
Indentations are very important in coding. In loops, you give indentation to specify a block of code to be executed inside a loop. In the same way, in this case, line 2 and line 3 only are a seperate block. Line 4, 5 and 6 must be out of the block for you to get the result. Hope this helps!
The correct code would be
def area(l,b):
a=l*b
print(“Area is:”,a)
area(4,6)
area(5,8)
area(2,100)
The problem in your code was that you didnt follow the indentation properly and the last three statements are also included in the function definition
Indentation is very important for coding properly so if you give proper indentation in line number 2 and 3 it will show output properly
The code is proper it is just that there is indentation problem.
def area(l,b):
a=l*b
print(“Area is :”,a)
area(4,6)
area(5,8)
area(2,100)
For your reference i have written the code with proper indentation in 4th to 6th line there is no need of space because of the space it has been taken as the part of the function whereas it is the part of the main body of the code.
There is an indention error at lines 4,5,6. since they are not part of the function block they should be written outside the function definition. just remove the tab space in lines 4,5,6. Then you will get the output.
This is an indentation problem.
Just remove space from lines 4, 5 and 6 and the code will work accordingly.
I hope this helps