Question

In: Computer Science

2,3,1 8,7,-3 1,2 Abc 0,4,3 -1,7,10 Develop a Python program which reads all the coefficient inputs...

2,3,1
8,7,-3
1,2
Abc
0,4,3
-1,7,10

Develop a Python program which reads all the coefficient inputs from coeff.txt and find the “real” roots of the equations. The following requirements must be met:

  • If there is no real root, then it must print “No real root”
  • If the coefficients inputs are inappropriate, then it must print “equation is not valid”
  • Roots are to be found using a function
  • All the outputs are to be written to an output text file

Solutions

Expert Solution

1). ANNSWER :

GIVENTHAT :

Check the output.txt file which display the equation with their roots and valid or invalid euqations.

Please check below screenshot for code indentation and output.

Code:

file=open("coeff.txt",'r')
list1=file.readlines()
list2=[]
for i in list1:
    list2.append(i.split(","))
file.close()
f = open("output.txt", "w+")
for i in list2:
    if(len(i)==3):
        a=int(i[0])
        b=int(i[1])
        c=i[2][0:len(i)-1]
        c=int(c)
        a=int(a)
        b=int(b)
        f.write(i[0]+"x^2+"+i[1]+"x+"+str(c)+" = ")
        d = (b ^ 2) - (4 * a * (c))
        if (d < 0):
            f.write("No real roots or Roots are imaginary \n")
        else:
            root1 = (-b + d) / 2 * a
            root2 = (-b - d) / 2 * a
            f.write("Roots are "+ str(round(root1, 2))+"\t"+str(round(root2, 2))+"\n")
    else:
        f.write("Equations are not valid \n")
f.close()

Output:


Related Solutions

Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs...
Using Python. Write a program that reads a sequence (unknown number of inputs) of integer inputs and prints the number of even and odd inputs in the sequence. please explain. Thanks
1)  Write a python program that opens a file, reads all of the lines into a list...
1)  Write a python program that opens a file, reads all of the lines into a list of strings, and closes the file. Use the Readlines() method. Test your programing using the names.txt file provided. 2) Convert the program into a function called loadFile, that receives the file name as a parameter and returns a list of strings. 3) Write a main routine that calls loadFIle three times to load the three data files given into three lists. Then choose a...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Python 3 Fix the code so the program reads the file and see if the bar...
Python 3 Fix the code so the program reads the file and see if the bar code was already inputted 3 times if so, it ishows a warning indicating that the item was already tested 3 times Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
In java P4.7 Following Section 4.9, develop a program that reads a string and removes all...
In java P4.7 Following Section 4.9, develop a program that reads a string and removes all duplicates. For example, if the input is Mississippi, print Misp. Start small and just print the first letter. Then print the first letter and true if the letter is not duplicated elsewhere, false otherwise. (Look for it in the remaining string, by using the substring and indexOf method). Next, do the same for the first two letters, and print out for each letter whether...
P4.7 Following Section 4.9, develop a program that reads a string and removes all duplicates. For...
P4.7 Following Section 4.9, develop a program that reads a string and removes all duplicates. For example, if the input is Mississippi, print Misp. Start small and just print the first letter. Then print the first letter and true if the letter is not duplicated elsewhere, false otherwise. (Look for it in the remaining string, by using the substring and indexOf method). Next, do the same for the first two letters, and print out for each letter whether or not...
In Python b) Modify your program that reads 3 grades from the user (and computes the...
In Python b) Modify your program that reads 3 grades from the user (and computes the average and letter grade) so that it uses a while loop to read the 3 grades. In the loop body, you will just read one grade and update other variables appropriately. The loop header will ensure 3 iterations. c) Modify your program in part b so that it asks the user how many grades there are and uses a while loop to read that...
Using Python 3 Write a program that reads the 4letterwords.txt file and outputs a file called...
Using Python 3 Write a program that reads the 4letterwords.txt file and outputs a file called 4letterwords.out that has every word found in 4letterwords.txt but each word on one line. Any leading and trailing blank spaces must be removed in the output file.
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Write a Python program, phone.py, that inputs a string of characters which represent a vanity telephone...
Write a Python program, phone.py, that inputs a string of characters which represent a vanity telephone number, e.g., 800-MYPYTHON, and prints the all numeric equivalent, 800-69798466. You should implement this using a loop construct to process each character from left to right. Build a new string that is the all numeric equivalent and then print the string.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT