本节练习
Topic source# -*- coding: utf-8 -*-
import math
a=input('please input a=')
b=input('please input b=')
c=input('please input c=')
a=int(a)
b=int(b)
c=int(c)
print('the equation you input is %dx^2 + %dx + %d' %(a,b,c))
def equation(a,b,c):
if(b*b-4*a*c<0):
print('the equation does not have solutions')
exit()
else:
x1=round((-b+math.sqrt(b*b-4*a*c))/(2*a),2)
x2=round((-b-math.sqrt(b*b-4*a*c))/(2*a),2)
print('the solutions of the equation is x1=%.2f, x2=%.2f' %(x1,x2))
return x1,x2
x1,x2=equation(a,b,c)
- 1
心灵旅者