Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions