0

help with task

Overload operators We are improving our drawing app. Our application must support addition and comparison of two objects Shape. Add appropriate methods to make it possible to add + and compare using the greater than > operator for the Shape class. The addition should return a new object with the sum of the width and height of the operands, and the comparison should return the result of comparing the area of the objects. https://sololearn.com/compiler-playground/cVR0H9SfCt62/?ref=app

16th Feb 2024, 7:15 AM
Сапиюлла
Сапиюлла - avatar
7 Antworten
+ 1
Сапиюлла , OK. Here's a stronger hint then. These are the names of the special methods you must define to support + and >. __add__ https://docs.python.org/3/reference/datamodel.html#object.__add__ __gt__ (gt means "greater than") https://docs.python.org/3/reference/datamodel.html#object.__gt__ Did the lessons before that task explain how to define a special method? Save your new code and share a new link if you want other people or me to help analyze it.
17th Feb 2024, 8:42 PM
Rain
Rain - avatar
+ 7
Сапиюлла , i guess your question maybe about *operator overloading*. anyway - can you please provide the: > tutorial name > lesson or exercise name
16th Feb 2024, 7:18 AM
Lothar
Lothar - avatar
+ 1
well done, i'm fixed problem!
18th Feb 2024, 8:31 AM
Сапиюлла
Сапиюлла - avatar
0
Сапиюлла , I see you haven't tried adding anything under "# your code" yet. People who try something generally get better advice, because it's more fun to analyze someone's code than to write it for them. Hint, you'll have to define two special methods in the Shape class to support the + and > operators. Here are some of the official docs. They can be a little thick to read, so ask again if you misunderstand any specific part. Glossary - special method https://docs.python.org/3/glossary.html#term-special-method Special method names https://docs.python.org/3/reference/datamodel.html#special-method-names
16th Feb 2024, 10:58 PM
Rain
Rain - avatar
0
, I'm sorry, I've just tried it more than 20 times and I'm already desperate.I take up the task again, but everything is even.Therefore, I decided to give such a clean code to understand magical methods by example.Once again, I apologize for my mistake.
17th Feb 2024, 7:16 PM
Сапиюлла
Сапиюлла - avatar
0
Сапиюлла , Awesome. Looks great. 👍 Now you can add [Solved] to the title, so it might help someone else who finds it in a search. Maybe add tags for 'operator' and 'overloading' too.
18th Feb 2024, 8:34 AM
Rain
Rain - avatar
0
Rain, ok, that’s exactly what I’ll do, after all, helping people like me will look very noble!
18th Feb 2024, 6:50 PM
Сапиюлла
Сапиюлла - avatar