Requirements
By the user randomly given a two times equation coefficients a, B, C, to calculate the solution of a two-time equation
Source Code
Import Cmath #包含复数运算import mathimport sysdef get_float (msg, AL Low_zero): x = None while X was none:try:x = float (input (msg)) if not Allow_zero and a BS (x) < sys.float_info.epsilon: #sys. Float_info.epsilon is a floating-point 0 print ("Zero is not allowed") x = None except ValueError as Err:print (err) return XPrint ("Ax\n{superscript" + bx + c = 0 ") #\n{name} gives the specified Unicode character a = Get_float (" Enter a: ", False) b = Get_float (" Enter B: ", True) C = Get_float ("Enter C:", True) x1 = Nonex2 = Nonediscriminant = (b * * 2)-(4 * A * c) if discriminant = = 0:x1 =-(b/( 2 * a)) else:if discriminant > 0:root = math.sqrt (discriminant) Else: # discriminant < 0 root = CMATH.SQRT (discriminant) x1 = (-B + root)/(2 * a) x2 = (-b-root)/(2 * a) equation = ("{0}x\n{superscript + {1}x + {2} = 0 " "\n{rightwards ARROW} x = {3}"). Format (A, B, C, x1) If X2 is not none:equation + = "or X = {0}". Format (x2) print (E quation)
If you have any questions, welcome to my public question ~
One day in python----calculation of the two-time equation of a dollar