Quadratic nth Term
This commit is contained in:
parent
b82687edbb
commit
120692ccf7
2 changed files with 22 additions and 0 deletions
20
python/calculators/quadratic nth term.py
Normal file
20
python/calculators/quadratic nth term.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import operator
|
||||
|
||||
def diff(a):
|
||||
return list(map(operator.sub, a[1:], a[:-1]))
|
||||
|
||||
sequence = [-0.5,1,4.5,10,17.5]
|
||||
row1 = diff(sequence)
|
||||
row2 = diff(row1)
|
||||
|
||||
a = row2[0] / 2
|
||||
b = row1[0] - (3 * a)
|
||||
c = sequence[0] - a - b
|
||||
|
||||
print('''
|
||||
a = {0}
|
||||
b = {1}
|
||||
c = {2}
|
||||
|
||||
Equation: {0}n^2 + {1}n + {2}
|
||||
'''.format(a, b, c))
|
|
@ -36,3 +36,5 @@ Here you can find a bunch of random work from my GCSE Computer Science class dum
|
|||
- [12 - Evil](python/pythonchallenge.com/12%20-%20Evil.py)
|
||||
- [13 - Disproportional](python/pythonchallenge.com/13%20-%20Disproportional.py)
|
||||
- [14 - Italy](python/pythonchallenge.com/14%20-%20Italy.py)
|
||||
- [Calculators](python/calculators)
|
||||
- [Quadratic nth Term](python/calculators/quadratic%20nth%20term.py)
|
||||
|
|
Loading…
Reference in a new issue