0

# What's wrong with my def code?

I need to calculate the area of a rectangle. What's wrong with my code? length = int(input()) width = int(input()) def area (length, width): print(length*width) if length == width: print('Square')

13 Answers

+ 4

What is it supposed to do exactly?
You have never called your function...

+ 4

You can do it like this:
1. Define a function
2. Get the the input
3. Call the function
def area(a, b):
if a == b:
print("Square")
print(a*b)
length = int(input())
width = int(input())
area(length, width)

+ 2

def area(a, b):
print(a * b)
if a == b:
print("Square")

+ 1

Call the function before printing 'Square'

0

Supposed to multiply length by width. And print 'Square' if they are identical

0

How do I make a code that will show the result first, and then Square?
I tried moving it around, and it showed errors

0

ariPT call area function before "if length == width:"

0

Or simply remove function declaration and leave print instruction

0

Thank you all.
I'm very much a beginner, and am still having trouble, despite your suggestions.
Could one of you please write a full code? I'm trying to see what I missed

0

def area(a, b):
print(a*b)
if a == b:
print("Square")
length = int(input())
width = int(input())
area(length, width)

0

Thank you!
Why do I need to define area both as a,b and as length,width?

0

You can call them what you want. This version should only show you, that the variables inside a function are others then the variables outside the function.

0

Thank you very much, I appreciate your help