subject

Now it's your turn. Implement a class for representing segments. We want to be able to create an interval with: s = Interval(2, 3) Once we have an interval, we want to be able to ask for its length, and for the position of its center:
s. length
s. center Given two intervals, we also want to implement a method intersect that tells us if they intersect or not. There are many ways of doing this; perhaps the simplest is to rely on the properties length and center developed above. Each of these methods can be implemented in one line of code, except for the initializer, which takes two.
class Interval(object):
def __init_(self, a, b):
self. a = a property def length(self):
**Returns the length of the interval."**
return self. a
def center(self):
"*"Returns the center of the interval."**
return self. b det intersects(self, other):
***Returns True/False depending on whether the interval intersects with interval other."**
if a / b = 2
return true
else
return false

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, robert7248
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
image
Computers and Technology, 23.06.2019 01:10, kristofwr3444
Are special combinations of keys that tell a computer to perform a command. keypads multi-keys combinations shortcuts
Answers: 1
image
Computers and Technology, 23.06.2019 08:30, mai1261
Helen's credit card has an apr of 15.32% and a grace period of 17 days and helen pays her balance in the full every month. if her last billing cycle ended on september 26, 2009, and she made her payment on october 11, 2009, did she owe any interest on her last statement's balance?
Answers: 3
image
Computers and Technology, 23.06.2019 13:30, powellmj9216
Spoons are designed to be used for: spring hammering. applying body filler. identifying high and low spots. sanding highly formed areas.
Answers: 3
You know the right answer?
Now it's your turn. Implement a class for representing segments. We want to be able to create an int...

Questions in other subjects:

Konu
Mathematics, 14.01.2021 14:00
Konu
Mathematics, 14.01.2021 14:00
Konu
Mathematics, 14.01.2021 14:00
Konu
Mathematics, 14.01.2021 14:00