+ 8
Area of rectangle, failed in test case#2. Can't figure out how? Expected output matches with my answer.
I tried to solve the area of rectangle problem. I am still failed test case#2 though the output matches with the expected output. Also, I feel that the code may be written in simpler way. Any comments? length = int(input()) width = int(input()) def area(length, width): #your code goes here return int(length) * int(width) area=area(length,width) if length == width: print(area, '\n'"Square") else: print(area)
21 ответ
+ 4
length = int(input())
width = int(input())
if length == width:
print(area +"Square")
else:
print(area)
+ 3
Its actually my code which i have solved early i hope this might help you follow me if wish
+ 3
Thanks for correction sir
+ 2
Please give me the topic name so that i could help you further
+ 2
length = int(input())
width = int(input())
def area(length, width):
if length == width:
print(length*width)
print("Square")
else:
print(length*width)
area(length, width)
+ 2
Amitayush
Your code worked but there is no need to write same things in if and else statement.
like print(length * width) is written in both statement. Even you will get same result without if else
+ 2
Arvind Kumar me too😥😥😥
+ 1
Rajat Banerjee
You have to print area as well as "Square" if both sides are equal.
print(area)
if length==width:
print ("Square")
+ 1
Thank you so much for all your help and support 💗
+ 1
For some weird reason both Amitayush and Silva's code failed test#2, while AJ#Learn with me worked.
+ 1
Use @ before name to tag people.
+ 1
Amitayush Function arguments
+ 1
Amitayush Thank you.
+ 1
I Am Groot ! see bro if you don't use it two times then you can't get area of the rectangle or any shape other than square
+ 1
Bro I too faced the same problems in Python , now those problems are looking impossible for me😟😟
0
Amitayush
We can get just see this
area = length * width
print(area)
if length==width:
print ("Square")
0
Amitayush
See your code, you have written
print (length * width) in both if and else part so area will always print in both case.
0
Amitayush
Welcome
I am a teacher in this type of coding because of 5 years IT experience.
I see daily this type of mistake by juniors.
0
Hello
0
length = int(input())
width = int(input())
def area(length, width):
if length == width:
print(length*width)
print("Square")
else:
print(length*width)
area(length, width)