class Line: '''write your codes below (don't forget to change the doc strings)''' def __init__(self, k, b): '''write your codes below (don't forget to change the doc strings)''' def __repr__(self): '''printable representation of the line by equation y = k*x+b''' return 'line y = %r*x + %r' % (self.k, self.b) def __add__(self,other): '''write your codes below (don't forget to change the doc strings)''' def intersect(self,other): '''write your codes below (don't forget to change the doc strings)'''

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

class Line:
'''write your codes below (don't forget to change the doc strings)'''

def __init__(self, k, b):
'''write your codes below (don't forget to change the doc strings)'''

def __repr__(self):
'''printable representation of the line by equation y = k*x+b'''
return 'line y = %r*x + %r' % (self.k, self.b)

def __add__(self,other):
'''write your codes below (don't forget to change the doc strings)'''

def intersect(self,other):
'''write your codes below (don't forget to change the doc strings)'''

When your code is done, run it and test the class with following piplines - Please re-run and save the results below.
In [7]:
I line1
Line(2,1)
Line(1,2)
%3D
line2 =
line3 = line1+line2
In [8]:
I line3
Out[8]: line y = 3*x + 3
In [9]:
I point = 1ine1.intersect(line2)
print(point)
[1.0, 3.0]
Transcribed Image Text:When your code is done, run it and test the class with following piplines - Please re-run and save the results below. In [7]: I line1 Line(2,1) Line(1,2) %3D line2 = line3 = line1+line2 In [8]: I line3 Out[8]: line y = 3*x + 3 In [9]: I point = 1ine1.intersect(line2) print(point) [1.0, 3.0]
jupyter homework_3 Last Checkpoint: a day ago (autosaved)
Logout
File
Edit
View
Insert
Cell
Kernel
Widgets
Help
Not Trusted
|Python 3 O
Run
Markdown
Problem 2: Line Class
Define the class called Line which represents a line with equation y = kx + b with input slope k and intercept b to initialize the instances. It should include:
attributes named k and b to represent slope and intercept.
method named intersect to return the list, containing coordinates of the intersection point of two lines.
support for + operator to compute the addition of two equations. The sum of two Line objects y = kjx + b1 and y = k2x + b2 is defined as the line
y = (k1 + k2)x + bj + b2.
printable representation for the equation of line, which we have already defined in
_repr_ speical method below.
In [5]:
I class Line:
''write your codes below (don't forget to change the doc strings)''
def _init_(self, k, b):
'''write your codes below (don't forget to change the doc strings)''
_repr_(self):
'''printable representation of the line by equation y =
return 'line y
def
k*x+b'
%r*x + %r' % (self.k, self.b)
add_(self,other):
''write your codes below (don't forget to change the doc strings)'
def
def intersect(self,other):
'''write your codes below (don't forget to change the doc strings)''
When your code is done, run it and test the class with following piplines - Please re-run and save the results below.
In [7]:
I line1 =
Line(2,1)
Line(1,2)
line2 =
line3 = line1+line2
In [8]:
I line3
Out[81:
lino -
Transcribed Image Text:jupyter homework_3 Last Checkpoint: a day ago (autosaved) Logout File Edit View Insert Cell Kernel Widgets Help Not Trusted |Python 3 O Run Markdown Problem 2: Line Class Define the class called Line which represents a line with equation y = kx + b with input slope k and intercept b to initialize the instances. It should include: attributes named k and b to represent slope and intercept. method named intersect to return the list, containing coordinates of the intersection point of two lines. support for + operator to compute the addition of two equations. The sum of two Line objects y = kjx + b1 and y = k2x + b2 is defined as the line y = (k1 + k2)x + bj + b2. printable representation for the equation of line, which we have already defined in _repr_ speical method below. In [5]: I class Line: ''write your codes below (don't forget to change the doc strings)'' def _init_(self, k, b): '''write your codes below (don't forget to change the doc strings)'' _repr_(self): '''printable representation of the line by equation y = return 'line y def k*x+b' %r*x + %r' % (self.k, self.b) add_(self,other): ''write your codes below (don't forget to change the doc strings)' def def intersect(self,other): '''write your codes below (don't forget to change the doc strings)'' When your code is done, run it and test the class with following piplines - Please re-run and save the results below. In [7]: I line1 = Line(2,1) Line(1,2) line2 = line3 = line1+line2 In [8]: I line3 Out[81: lino -
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education