Question: Python 3.6- I have a txt file with numbers on each line. I've created a source code to read from that file and write to
Python 3.6- I have a txt file with numbers on each line. I've created a source code to read from that file and write to another file that uses quadratic forumla to solve for x intercepts. My problem is that I don't know how to read line by line and transfer that information to a new created txt file in Python Macbook OS. I've included the source code. So, the goal is to take info from txt file and write new source code that allows me to read and write to new txt file. The new txt file should look very similar to last figure provided
. Provide indented source code and new txt file screenshot. Thanks



Here's the source code copy and paste version:
def quadratic(): with open('quadratic.txt', 'r') as f: # read-only file with open('results.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 print('f(x) =', a, 'x^2+', b, 'x+', c, " which only has x intercept at", 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 print('f(x) =', a, 'x^2+', b, 'x+', c, "with x-intercepts at ", \ format(x1, ',.2f'), " and", format(x2, ',.2f')) # print to two decimal places except: if len(line) != 3: print('Wrong amount of coefficients!') else: if str() in line: print('Invalid coefficients or constant!') quadratic() Python 3.6- I made a source code to find x intercepts using quadratic equation formula for data in txt file (shown below) quadratic.txt 5 7 1 6 10 9 8 20 10 100 600 600 63 2 5 6 a 0 5 6 1 2 1 8 10 9 -5 -5|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
