2021年1月27日星期三

quadratic formula using python

Trying to create a program that takes in three arguments that represent the a, b, and c values in the quadratic formula. The values should be to two decimal places. You do not need to account for imaginary values. Then print out both roots in the form:

The solutions are x and y    Where x and y correspond to the positive and negative roots, respectively.  

Having issues with my code: ''' import math

a = float(input('please input a number:'))

b = float(input('please input a number3:'))

c = float(input('please input a number2:'))

d = (b**2) - (4ac)

sol1 = str(round((-b-cmath.sqrt(d))/(2*a),2))

sol2 = str(round((-b+cmath.sqrt(d))/(2*a),2))

print('The solution are {1.real:.2f} and {0.real:.2f}'.format(sol1,sol2)) '''

https://stackoverflow.com/questions/65929638/quadratic-formula-using-python January 28, 2021 at 09:08AM

没有评论:

发表评论