Question: coding in python need help getting sub to work. For input: I1=Interval(1,4) I2=Interval(-2,-1) Want I1+I2 Ouput: [-1,3] import numpy as np import matplotlib.pyplot as plt

coding in python

need help getting sub to work.

For input:

I1=Interval(1,4)

I2=Interval(-2,-1)

Want I1+I2

Ouput: [-1,3]

coding in python need help getting sub to work. For input: I1=Interval(1,4)

import numpy as np

import matplotlib.pyplot as plt

from scipy import *

from pylab import *

import sys

import scipy.integrate as si

from scipy.integrate import quad

class Interval:

def __init__(self,a, b=None):

if b==None:

self.b=a

self.a=a

self.b=b

m=[self.a,self.b]

def sub(self,second):

c=self.second

d=self.second

m=[self.a-c,self.b-d]

#I1=Interval(1,4)

#I2=Interval(-2,-1)

#want I1-I2 to perform subtraction such that the return is [a-c,b-d]

def __repr__(self):

return'['+str(self.a)+','+str(self.b)+']'

def __str__(self):

return'['+str(self.a)+','+str(self.b)+']'

9 import numpy as np 10 import matplotlib.pyplot as plt 11 from scipy import * 12 from pylab import * 13 import sys 14 import scipy.integrate as si 15 from scipy.integrate import quad 16 17 class Interval: 18 19 def.-init-(self,a, b=None): 20 21 if bE None: self.b-a self.a self.b-b m= [self. a, sel f,b] =a 23 24 25 26 def sub(self,second): 27 28 29 30 31 32 c=self. Second d-self.second m-[self.a-c,self.b-d] #11Interval (1,4) #12-Interval (-2,-1) #want 11-12 to perform subtraction such that the return is [a-c , b-d] -repr-(self): return' ['+str(self.a)+, +str(self.b)+'1 def 34 35 36 37 38 39 def str-(self): return' ['+str(self.a)+, +str(self.b)+'1

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!