#! /usr/bin/env python
#by techsolo & Poincare
#
#and now something completly different

def intro() : #welcoms message
        """
Python linear regressions           (o_
         by                         //\  (o_  (o_
      -techsolo-                    V_/_ (_)_ (_)_
#########################
        """
        pass
print intro.__doc__

def vraag_waarde(variabele,teller):
	print "geef een waarde voor",variabele,teller,": "
	geldig="nee"
	while "nee"==geldig:
		getal = raw_input (">")
		try:
			getal_float=float(getal)
		except(ValueError):
			getal_is_float="nee"
		else:
			getal_is_float="ja"
		if ( "stop"==getal or "ja"==getal_is_float):
			geldig="ja"
		else:
			geldig="nee"
			print "Ongeldige invoer, probeer opnieuw"
			print "geef een waarde voor ",variabele,teller,": "
	return getal

LijstX=[]
LijstY=[]

n=0
maxx = 0
minx = 0
maxy = 0
miny = 0
nogeenmeting="ja"

while "ja"==nogeenmeting:
	x = vraag_waarde("x",n+1)
	if "stop" != x:
		y = vraag_waarde("y",n+1)
		if float(y)>float(maxy):
			maxy=y
		if float(y)<float(miny):
			miny=y		
		if float(x)>float(maxx):
			maxx=x
		if float(x)<float(minx):
			minx=x	
	nogeenmeting="nee"
	if x != "stop" and y != "stop":
		nogeenmeting="ja"	
		LijstX.append(float(x))
		LijstY.append(float(y))
		n = n+1

print "Einde\n\n"
print LijstX
print LijstY, "\n"
print n," getallen\n\n"

teller=0
Som_x=0
Som_y=0
Som_xy=0
Som_xsq=0

while teller < n:
	x=LijstX[teller]
	y=LijstY[teller]
	print teller,"=>",x,':',y
	Som_x=Som_x+x
	Som_y=Som_y+y
	Som_xy=Som_xy+x*y
	Som_xsq=Som_xsq+x*x
	teller=teller+1

#teller=0

#while teller < n:
#	x=LijstX[teller]
#	y=LijstY[teller]
#	teller=teller+1

a=(n*Som_xy-Som_x*Som_y)/(n*Som_xsq-Som_x*Som_x)
b=(Som_xsq*Som_y-Som_x*Som_xy)/(n*Som_xsq-Som_x*Som_x)

print "\na:",a
print "b:",b
print "\nfunctie is Y=",a,"X +",b, "\n"
print "max X=", maxx
print "max y=", maxy
print "min X=", minx
print "min Y=", miny

#We are the knights who say Ni!
print "\nWe are the knights who say Ni!"
Lni=[]
Lni.append("Ni!")
Lni=Lni * 4
print Lni
