Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.6- Okay, I got a problem that can potentially be solved quickly. The first img is a txt file called quad.txt. The second is

Python 3.6- Okay, I got a problem that can potentially be solved quickly. The first img is a txt file called quad.txt. The second is source code that writes( to a diff txt file called quadresults.txt) the x intercepts by solving qudratic equation.

For line 9, I should get f(x) = 1x^2 +2x+1 which only has x intercept at (-1,0,0). However , I get Wrong amt of coefficients! as the output which means that my script needs correction. Correct the source code ,such as the quadratic forumula, so it displays for line 9 that f(x)= 1x^2 +2x + 1. Thanks

image text in transcribed

def quadratic(): with open('quad.txt', 'r') as f: # read-only file with open('quadresults.txt', 'w') as w: # opens and writes on file for line in f: try: a, b, c = (int(x) for x in line.split()) d = int(b) ** 2 - 4 * int(a) * int(c) # discriminant if d elif d == 0: x = (-int(b) + (int(b) ** 2 - 4 * int(a) * int(c)) ** .5) / 2 * int(a) # one solution w.write('f(x) =' + str(a), 'x^2+'+ str(b)+ 'x+'+ str(c)+ " which only has x intercept at"+ str(x) + ' ') else: x1 = (-int(b) + (int(b) ** 2 - 4 * int(a) * int(c)) ** .5) / 2 * int(a) x2 = (-int(b) - (int(b) ** 2 - 4 * int(a) * int(c)) ** .5) / 2 * int(a) # for two solutions w.write('f(x) ='+ str(a)+ 'x^2+'+ str(b)+ 'x+'+ str(c)+ "with x-intercepts at "+ \ format(x1, ',.2f')+ " and"+ format(x2, ',.2f') + ' ') # print to two decimal places except Exception as e: if len(line) != 3: w.write('Wrong amount of coefficients! ') else: if str() in line: w.write('Invalid coefficients or constant! ') quadratic() 

image text in transcribed

5 7 1 6 10 9 8 20 10 100 600 600 63 2 62 (3 9 1 2 1 -9-5-5

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

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago