# Author: Steven Carr # Last Edited: October 2021 # Calculates the two roots of a given quadratic equation import math import stdio import sys # Accept a (float), b (float), and c (float) as command-line arguments. a = float(sys.argv[1]) b = float(sys.argv[2]) c = float(sys.argv[3]) # If a is 0, write the message 'Value of a must not be 0' to standard output. if a == 0: stdio.writeln('Value of a must not be 0') else: # Compute discriminant (b^2 - 4ac). d = ((b ** 2) - (4 * a * c)) # If discriminant is negative, write the message 'Value of discriminant must not be # negative' to standard output. if d < 0: stdio.writeln('Value of discriminant must not be negative') else: # Compute the two roots of the quadratic equation ax^2 + bx + c = 0. sr = d ** .5 root1 = ((-b) + sr) / (2 * a) root2 = ((-b) - sr) / (2 * a) # Write the two roots to standard output, separated by a space. stdio.write(root1) stdio.write(' ') stdio.writeln(root2)