Brendan Gillatt
Quadratic Printer

What It Does & Why

This simple script prints the terms of a quadratic sequence given a formula and a range.

Please note that, due to its extreme simplicity, I have licensed this with the MIT license.

Usage

The script is launched from the command line without arguments. Each part of the formula is entered when prompted and then a range.

Get The Code

Requirements:

Download TXT source

#! /usr/local/bin/python
#-*- coding: latin-1 -*-
#
# Brendan Gillatt
#
# MIT License
#

#Prints the terms of a given quadratic sequence.
#E.G. 3n²+2n+1 would output 6, 17, 34, etc.

A = int(raw_input('  ný: ')) #Enter part like the above '3n²'
B = int(raw_input('   n: ')) #Enter part like the above '2n'
C = int(raw_input('  +-: ')) #Enter part like the above '1'
range1 = int(raw_input('from: ')) #Enter start term
range2 = int(raw_input('  to: ')) + 1 # Enter end term

#print ' '
#print 'Number | Term'
#print ' '

for count in range(range1, range2):
	first = A*count**2
	second = B*count
	third = C
	out = first + second + third
	print out, ' | ', count