def perm(str): if len(str) < 2: help.helper("perm") return None total = int(str[1]) pick = int(str[2]) return fact(total) / fact(total - pick)
def set(str): global vars if len(str) < 3: help.helper("set") return None if str[1] == 'x' or str[1] == 'y' or str[1] == 'a': print("Unable to set system variables") else: vars[str[1]] = float(str[2])
def get(str): if len(str) < 2: help.helper("get") return None global vars try: return vars[str[1]] except: pass
def plot(args): if len(args) < 2: help.helper("points") return None xlist = [] ylist = [] for x in args[1:]: pt = x.split(",") if len(pt) > 1: xlist.append(pt[0]) ylist.append(pt[1]) plt.plot(xlist,ylist,'o')
def plot(args): if len(args) < 2: help.helper("points") return None xlist = [] ylist = [] for x in args[1:]: pt = x.split(",") if len(pt) > 1: xlist.append(pt[0]) ylist.append(pt[1]) plt.plot(xlist, ylist, 'o')
def intersect(args): if len(args) < 4: help.helper("intersect") return None eq1 = args[1] eq2 = args[2] rg = range(int(float(args[3])),int(float(args[4]))) pts1x,pts1y = genpoints(eq1,rg,'x') pts2x,pts2y = genpoints(eq2,rg,'x') out = [] for x in rg: if pts1x[x] == pts2x[x] and pts1y[x] == pts2y[x]: out.append((pts1x[x],pts1y[x])) for x in out: print("(%s)\n" % (x,))
def sigma(args): # equation variable start end if len(args) < 4: help.helper("sigma") return None eq = args[1] var = args[2] start = int(float(args[3])) end = int(float(args[4])) result = 0 # end+1 for inclusive range for x in range(start,end+1): result += parser.evaluate(eq,{var:x}) print("%d" % result)
def intersect(args): if len(args) < 4: help.helper("intersect") return None eq1 = args[1] eq2 = args[2] rg = range(int(float(args[3])), int(float(args[4]))) pts1x, pts1y = genpoints(eq1, rg, 'x') pts2x, pts2y = genpoints(eq2, rg, 'x') out = [] for x in rg: if pts1x[x] == pts2x[x] and pts1y[x] == pts2y[x]: out.append((pts1x[x], pts1y[x])) for x in out: print("(%s)\n" % (x, ))
def stats(lst): if len(lst) < 2: help.helper("stats") return None list = [] for x in lst[1:]: list.append(int(x)) #print(list) st = {} try: st["mean"] = mean(list) st["standard deviation"] = stdev(list) st["median"] = median(list) st["mode"] = mode(list) except: pass for x, y in st.items(): print("%s = %d" % (x, y))
def stats(lst): if len(lst) < 2: help.helper("stats") return None list = [] for x in lst[1:]: list.append(int(x)) #print(list) st= {} try: st["mean"] = mean(list) st["standard deviation"] = stdev(list) st["median"] = median(list) st["mode"] = mode(list) except: pass for x,y in st.items(): print("%s = %d" % (x,y))
def graph(str): if len(str) < 4: help.helper("graph") return None global numfig try: plt.figure(int(str[5])) except: plt.figure(numfig) numfig += 1 plt.title(str[2]) plt.grid() start = int(float(str[3])) end = int(float(str[4])) rg = range(start, end) if str[1] == 'x': xeq(str[2], rg) elif str[1] == 'y': yeq(str[2], rg)
def graph(str): if len(str) < 4: help.helper("graph") return None global numfig try: plt.figure(int(str[5])) except: plt.figure(numfig) numfig += 1 plt.title(str[2]) plt.grid() start = int(float(str[3])) end = int(float(str[4])) rg = range(start,end) if str[1] == 'x': xeq(str[2],rg) elif str[1] == 'y': yeq(str[2],rg)
def combo(str): if len(str) < 2: help.helper("combo") total = int(str[1]) pick = int(str[2]) return fact(total) / (fact(pick) * fact(total - pick))