GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/QuadraticCalc.py at master · CHAOYUHONG/Python Expand file tree/ Copy pathQuadraticCalc.pyMore file actions 42 lines (37 loc) · 1.18 KB / Copy pathQuadraticCalc.pyFile metadata and controls42 lines (37 loc) · 1.18 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #GGearing #02/10/2017 #Simple script to calculate the quadratic formula of a sequence of numbers and #recognises when the sequence isn't quadratic def findLinear(numbers): ##find a & b of linear sequence output=[] a=numbers[1]-numbers[0] a1=numbers[2]-numbers[1] if a1==a: b=numbers[0]-a return (a,b) else: print("Sequence is not linear") sequence=[] first_difference=[] second_difference=[] for i in range(4): #input term=str(i+1) inp=int(input("Enter term "+term+": ")) sequence.append(inp) for i in range(3): gradient=sequence[i+1]-sequence[i] first_difference.append(gradient) for i in range(2): gradient=first_difference[i+1]-first_difference[i] second_difference.append(gradient) if second_difference[0]==second_difference[1]: #checks to see if consistent a=second_difference[0]/2 subs_diff=[] for i in range(4): n=i+1 num=a*(n*n) subs_diff.append((sequence[i])-num) b,c=findLinear(subs_diff) print("Nth term: "+str(a)+"n^2 + "+str(b)+"n + "+str(c)) #outputs nth term else: print("Sequence is not quadratic") |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |