#moreFunctions.py
# for second class on functions -- complete in class

from graphics import *

def between(x, end1, end2):
    """ return true if x is between end1 and end2 or equal to an end
    The order of end1 and end2 do not matter.
    """
    return end1 <= x <= end2 or end2 <= x <= end1


def inputInRange(prompt, end1, end2):
    """ return a value from the user in the proper range.
    This repeats until the user gives a legal value.
    The order of end1 and end2 do not matter.
    """
    fullPrompt = "%s (between %s and %s): " % (prompt, end1, end2)
    n = input(fullPrompt)
    while not between(n, end1, end2):
        print "Try again, carefully!"
        n = input(fullPrompt)
    return n

def distance(pt1, pt2):
    """ return the distance between Points pt1, pt2
    """
    dx = pt1.getX() - pt2.getX()
    dy = pt1.getY() - pt2.getY()
    return (dx*dx + dy*dy)**.5


def testBetween():
    a, b = input("Enter two numbers, comma separated: ")
    n = input("another number: ")
    if between(n, a, b):
        print "Is between"
    else:
        print "Not between"

def testDistance():
    win = GraphWin()
    text = Text(Point(100, 30),"Click twice")
    text.draw(win)
    pt1 = win.getMouse()
    pt1.draw(win)
    text.setText("Again...")
    pt2 = win.getMouse()
    Line(pt1, pt2).draw(win)
    d = distance(pt1, pt2)
    text.setText("Distance %.2f.\n  Click to quit" % d)
    win.getMouse()
    win.close()

def testInputRange():
    print "A legal value is %s" % inputInRange("Enter a number", 3, 7)

testBetween()
#testInputRange()
#testDistance()
