From 04f70d86b6a0e5d9882775b3e6c475ee8b1a76b0 Mon Sep 17 00:00:00 2001 From: newt Date: Mon, 21 Jun 2021 19:34:34 +0100 Subject: [PATCH] Quadratic nth Term --- python/calculators/quadratic nth term.py | 20 ++++++++++++++++++++ readme.md | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 python/calculators/quadratic nth term.py diff --git a/python/calculators/quadratic nth term.py b/python/calculators/quadratic nth term.py new file mode 100644 index 0000000..5cf5fda --- /dev/null +++ b/python/calculators/quadratic nth term.py @@ -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)) diff --git a/readme.md b/readme.md index cab45b8..50e18bc 100644 --- a/readme.md +++ b/readme.md @@ -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)