#! /usr/bin/python
import sys
import re
from math import *
p = r"(\d) *: *(\d) *, *(\d\.{0,1}\d{0,1})"
str = sys.argv[1]
func = sys.argv[2]
gg = re.search(p, str).groups()
x = float(gg[0])
end = float(gg[1])
step = float(gg[2])
while x <= end:
        print "x = ", x, func, "= ", eval(func)
        x += step                     

 

input

[b9715006@inl8 ~]$ ./numgen.py '0 : 2 , 0.5' 'x*sin(x)'
x =  0.0 x*sin(x) =  0.0
x =  0.5 x*sin(x) =  0.239712769302
x =  1.0 x*sin(x) =  0.841470984808
x =  1.5 x*sin(x) =  1.49624247991
x =  2.0 x*sin(x) =  1.81859485365


讓地獄深紅的天亮 發表在 痞客邦 PIXNET 留言(0) 人氣()