Question: Using Python 8.16 Implement a class myInt that behaves almost the same as the class int, except when trying to add an object of type

Using Python

8.16 Implement a class myInt that behaves almost the same as the class int, except when trying to add an object of type myInt. Then, this strange behavior occurs: >>> x = myInt(5) >>> x * 4 20 >>> x * (4 + 6) 50 >>> x + 6 'Whatever ...'

8.17 Implement your own string class myStr that behaves like class str except that: The addition (+) operator returns the sum of the lengths of the two strings (instead of the concatenation). The multiplication (*) operator returns the product of the lengths of the two strings. The two operands, for both operators, are assumed to be strings; the behavior of your im- plementation can be undefined if the second operand is not a string. >>> x = myStr('hello') >>> x + 'universe'13>>> x * 'universe' 40

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!