Not getting the result


not getting any output .

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

There is an indentation problem. In python it is very important to keep this in mind as there are no braces or curly brackets so it is of utmost importance

Hi @dhirajworked , the problem for your code is “INDENTATION”,
which is very important while programming in python.

You have to define the statement of the function by giving indentation.
And you have to call the function without giving that indentation.

I think I have clarified your doubt.
Thank you

There is an indentation problem here, so call the function without giving that identation.
The correct code would be as follows:
def area(l,b):
***a = l * b
***print("Area is: ",a)
area(4,6)
area(5,8)
area(2,100)

I have checked your program. The solution is simple. You have made a mistake with the indentations after line 3, so, the three times you have called the function area() have become a part of the function itself.

The correct code is this:
def area(l,b):
a=l*b
print (“Area is:”,a)
area(4,6)
area(5,8)
area(2,100)

Hope this helps.

There is an indentation error in lines 4,5 and 6
The correct progam is
def area(l,b):
__a=l*b
__print(“Area is:”,a)
area(4,6)
area(5,8)
area(2,100)
You will get the correct result for it
note: consider
as tab

Uh will be got soon soo noo problem

Here’s the corrected code:
Screenshot 2023-05-13 123657

You need to fix the indentation so that the function calls are at the same level as the function definition.
In your code, the function calls are written inside the function definition, the function calls should be moved outside the function definition to call the area() function with given values.

1 Like

The code you provided has indentation errors, which will lead to a SyntaxError. Additionally, there are some naming inconsistencies. Here’s the corrected version of the code:

def area(l, b):
    a = l * b
    print("Area is:", a)

area(4, 6)
area(5, 8)
area(2, 100)

The issues in your original code and their resolutions are as follows:

  1. Indentation: Python relies on proper indentation to define the structure of the code. In your code, the lines following the function definition and the function calls are indented incorrectly. They should be at the same level of indentation as the function definition.

By applying these correction, the code will execute without syntax errors, calculate the areas correctly, and print the results.

2 Likes

def area(l, b):
a = l * b
print(“Area is:”, a)

area(4, 10)
area(5, 12)
area(2, 14)
for that we get an output of
Area is 40
Area is 60
Area is 28

def area(l,b):
| a=lb
| print(“Area is :”,a)
| area(4,6)
| area(5,8)
| area(2,100)
The verticle line is the indentation(OF LINE1 def part). You give indentation to specify a block of code to be executed inside a loop. So, the correct way of writing this code will be:
def area(l,b):
a=l
b
print(“Area is :”,a)
area(4,6)
area(5,8)
area(2,100)

1 Like

Indentation Mistake