Learn python[1]
这几天我又看了些有关Python的书籍。尽管看了很多,但是写的少,所以还是云里雾里。今天写了一个解一元二次方程的简单程序。哈哈,弱爆了,但还是想炫一下。
# -*- coding: UTF-8 -*-
#! /usr/bin/env python
'''
Created on 2015-4-12
@author: Jerry
'''
import math
def jiefangcheng(a,b,c):
delta = b*b - 4*a*c
if delta < 0:
print "Error,The delta value is not right"
elif delta == 0:
print "x =", (-b)/(2*a)
else:
deltap = math.sqrt(delta)
x1 = (-b+ deltap)/(2*a)
x2 = (b + deltap)/(2*a)
print "x1= %.3f" % x1
print "x2= %.3f" % x2
jiefangcheng(1,3,1)