Course Solutions Uncategorized (Solved) : 1 Consider Following Code Class Myoperand Def Init Self Op Selfop1 Op Def Add Self Otherop Q32988956 . . . .

(Solved) : 1 Consider Following Code Class Myoperand Def Init Self Op Selfop1 Op Def Add Self Otherop Q32988956 . . . .

 

1. Consider the following code:

class MyOperand:

def __init__(self, op):

self.op1 = op

def __add__(self, otherOperand):

return ‘Result:’, self.op1 + otherOperand.op1

x = MyOperand(4)

y = MyOperand(5)

print(x+y)

x = MyOperand(“H”)

y = MyOperand(“i”)

print(x+y)

In the above code, when two instances of the class MyOperandi.e. x and y are added with

the + operator we see that the built-in function __add__ iscalled. Here, the + operator was

overloaded to add two numbers or concatenate two strings with anote that reads ‘Result’.

1- Include the __sub__ function in the above code and test itwith numbers, strings, and

lists. Explain the results.

i need the answer in python code please?

Expert Answer


An answer will be send

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

(Solved) : C Alter Code Deletes Occurances Given Element Form Template Void Unorderedlinkedlist Delet Q31820066 . . . .(Solved) : C Alter Code Deletes Occurances Given Element Form Template Void Unorderedlinkedlist Delet Q31820066 . . . .

<p><strong>In C++, Alter code so that it deletes all occurances ofa given element.  </strong></p><p><strong>Should be in form:</strong></p><p><strong>template <class Type><br/>void UnorderedLinkedList<Type>::deleteAll(const Type&deleteItem)<br/>{</strong></p><p><strong>//Here</strong></p><p><strong>}</strong></p><p>template <class Type></p><p>void UnorderedLinkedList<Type>::deleteSmallest()</p><p>{</p><p>{</p><p>NodeType<Type> *current = 0;</p><p>NodeType<Type> *trailCurrent = 0;</p><p>NodeType<Type> *small