Area of rectangle, failed in test case#2. Can't figure out how? Expected output matches with my answer. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

12th Dec 2020, 3:16 AM
Rajat Banerjee
Rajat Banerjee - avatar
21 Answers
+ 4
length = int(input()) width = int(input()) if length == width: print(area +"Square") else: print(area)
12th Dec 2020, 3:51 AM
Amitayush
Amitayush - avatar
+ 3
Its actually my code which i have solved early i hope this might help you follow me if wish
12th Dec 2020, 10:35 AM
Amitayush
Amitayush - avatar
+ 3
Thanks for correction sir
12th Dec 2020, 4:15 PM
Amitayush
Amitayush - avatar
+ 2
Please give me the topic name so that i could help you further
12th Dec 2020, 9:04 AM
Amitayush
Amitayush - avatar
+ 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)
12th Dec 2020, 10:35 AM
Amitayush
Amitayush - avatar
+ 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
12th Dec 2020, 11:58 AM
A͢J
A͢J - avatar
+ 2
Arvind Kumar me too😥😥😥
13th Dec 2020, 6:30 AM
Sneha Singh
Sneha Singh - avatar
+ 1
Rajat Banerjee You have to print area as well as "Square" if both sides are equal. print(area) if length==width: print ("Square")
12th Dec 2020, 4:07 AM
A͢J
A͢J - avatar
+ 1
Thank you so much for all your help and support 💗
12th Dec 2020, 8:11 AM
Rajat Banerjee
Rajat Banerjee - avatar
+ 1
For some weird reason both Amitayush and Silva's code failed test#2, while AJ#Learn with me worked.
12th Dec 2020, 8:20 AM
Rajat Banerjee
Rajat Banerjee - avatar
+ 1
Use @ before name to tag people.
12th Dec 2020, 8:42 AM
A͢J
A͢J - avatar
+ 1
Amitayush Function arguments
12th Dec 2020, 9:53 AM
Rajat Banerjee
Rajat Banerjee - avatar
+ 1
Amitayush Thank you.
12th Dec 2020, 12:06 PM
Rajat Banerjee
Rajat Banerjee - avatar
+ 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
12th Dec 2020, 4:09 PM
Amitayush
Amitayush - avatar
+ 1
Bro I too faced the same problems in Python , now those problems are looking impossible for me😟😟
13th Dec 2020, 6:24 AM
คгשเภ๔ кย๓คг
คгשเภ๔ кย๓คг - avatar
0
Amitayush We can get just see this area = length * width print(area) if length==width: print ("Square")
12th Dec 2020, 4:11 PM
A͢J
A͢J - avatar
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.
12th Dec 2020, 4:15 PM
A͢J
A͢J - avatar
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.
12th Dec 2020, 4:18 PM
A͢J
A͢J - avatar
0
Hello
13th Dec 2020, 5:12 PM
Tilek Kenjebekuulu
Tilek Kenjebekuulu - avatar
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)
16th Dec 2023, 11:44 AM
Azmeera Shanthi
Azmeera Shanthi - avatar