#!/usr/bin/env python3 # Display roots of quadratic equation. # example: qeq-trap.py 1 -4.6 4.08 # Import standard modules. import math import sys # Extract command-line arguments. a = float(sys.argv[1]) b = float(sys.argv[2]) c = float(sys.argv[3]) # Determinant. det = b**2 - 4 * a * c roots = None, None # Store roots as a tuple. try: roots = (-b + math.sqrt(det)) / (2 * a), (-b - math.sqrt(det)) / (2 * a) except ValueError: pass print(roots)