Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Written by *** for COMP9021 # # Implements two functions that both return a string: # - for line(), the equation of a line

# Written by *** for COMP9021 # # Implements two functions that both return a string: # - for line(), the equation of a line that goes through both points # provided as arguments; # - for parabola(), the equation of a parabola that has as roots the # values provided as arguments.

def line(point_1, point_2): '''It can be assumed that point_1 and point_2 are both tuples of 2 integers. The function is meant to return a string that represents the equation of a line that goes through both points, in case they are different; otherwise, the function returns None.

- If the line is vertical, then the function returns a string of the form 'x = b', with b the representation of a floating point number with 2 digits after the decimal point. - If the line is horizontal, then the function returns a string of the form 'y = b', with b the representation of a floating point number with 2 digits after the decimal point. - If the line is neither horizontal nor vertical, then - either the intercept is 0, in which case the function returns a string of the form 'y = ax', with a the representation of a floating point number with 2 digits after the decimal point; - or the intercept is not 0, in which case the function returns a string of the form 'y = ax b' with a and b representations of floating point numbers with 2 digits after the decimal point, and with b positive. ''' return '' ### REPLACE THE RETURN STATEMENT ABOVE WITH YOUR CODE def parabola(*roots): '''It can be assumed that roots consists of nothing but integers.

The function is supposed to return a string that represents a second-order equation with 1 as factor of x^2, such that the roots of the equation are precisely the members of the argument root, in case such an equation exists; otherwise, the function returns None.

The returned string should have the form 'x^2 bx c' with b and c positive integers, modulo the following conditions. - In case b is 0, ' + bx' is omitted. - In case c is 0, '+ c' is omitted. - In case b is 1, b is omitted. ''' return '' ### REPLACE THE RETURN STATEMENT ABOVE WITH YOUR CODE

image text in transcribed

= >>> from quiz_2 import * >>> line(0, 0), (0, 0)) >>> line((0, -3), (0, 0)) 'x = 0.00 >>> line((-3, -3), (-3, 7)) x = -3.00 >>> line ((8, 0), (5, 0)) 'y 0.00 >>> line (8, 3), (-5, 3)) 'y = 3.00 >>> line((-3, -3), (0, 0)) 'y 1.00x' >>> line ((3, -3), (0, 0)) 'y = -1.00x' >>> line ((1, 2), (2, 3)) 'y = 1.00x + 1.00 >>> line((-1, -2), (0, -1)) 'y = 1.00x - 1.00' >>> line ((3, -3), (2, -4)) 'y = 1.00x - 6.00 >>> line ((12, 5), (13, 29)) 'y 24.00x 283.00 >>> line((-1, -2), (7, 8)) 'y = 1.25x - 0.75' >>> line((-231, 87240), (73, 2987452)) 'y = 9540.17x + 2291019.51' >>> parabola () >>> parabola (1, 0, 2) >>> parabola (0) 'x^2 = 0 >>> parabola(1, 1, 1, 1) 'x^2 - 2x + 1 = 0 >>> parabola (1, 0, 0, 1, 1, 0, 1) 'x^2 - x = 0 >>> parabola (7, -4, 7) 'x^2 - 3x - 28 = 0 >>> parabola(-3, -11) 'x^2 + 14x + 33 = 0 >>> parabola(100, -4, -4, -4, 100) 'x^2 - 96x - 400 = 0

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions