############## This is the stuff for making the graph.  
############## Your program is at the bottom
import turtle
from math import *

def smallest_element(values):
  smallest=1.0E99
  for i in range(0,len(values)):
    if values[i] < smallest:
      smallest = values[i]
  return smallest    

def biggest_element(values):
  biggest=1.0E-99
  for i in range(0,len(values)):
    if values[i] > biggest:
      biggest = values[i]
  return biggest    

def graph_xy(x_values,y_values):
  t = turtle.Pen()                # "Pen" must start with a capital P!
  t.speed(0)                      # 0 is fastest
  t.hideturtle()
  window_max_x = t.window_width()/2.1
  window_max_y = t.window_height()/2.1
  print "window_max_x",window_max_x
  print "window_max_y",window_max_y
  biggest_x=biggest_element(x_values)
  biggest_y=biggest_element(y_values)
  print "Biggest x value=",biggest_x
  print "Biggest y value=",biggest_y
  smallest_x=smallest_element(x_values)
  smallest_y=smallest_element(y_values)
  print "Smallest x value=",smallest_x
  print "Smallest y value=",smallest_y
  t.penup()
  for i in range(0,len(x_values)):
    x=1.0*(-smallest_x+x_values[i])/(biggest_x-smallest_x)  #Make x be tween 0 and 1
    #print "norm x=",x
    y=1.0*(-smallest_y+y_values[i])/(biggest_y-smallest_y)  #Make y be tween 0 and 1
    #print "norm y=",y
    x=-window_max_x+(x*2.0*window_max_x)  #Make x have the full window width range
    y=-window_max_y+(y*2.0*window_max_y)  #Make x have the full window height range
    t.goto(x,y)
    t.pendown()
  # Draw a box
  t.penup()
  t.goto(-window_max_x,-window_max_y)
  t.pendown()
  t.goto(-window_max_x,window_max_y)
  t.goto(window_max_x,window_max_y)
  t.goto(window_max_x,-window_max_y)
  t.goto(-window_max_x,-window_max_y)  
  
  # Draw x and y axes
  # Draw the X axis
  t.penup()
  y=1.0*(-smallest_y+0)/(biggest_y-smallest_y)  #Make y be tween 0 and 1
  y=-window_max_y+(y*2.0*window_max_y)  #Make y have the full window width range
  t.goto(-window_max_x,y)
  t.pendown()
  t.goto(window_max_x,y)      #X axis
  t.write("x",align="right",font=("Arial", 18, "normal"))

  # Draw the Y axis
  t.penup()
  x=1.0*(-smallest_x+0)/(biggest_x-smallest_x)  #Make x be tween 0 and 1
  x=-window_max_x+(x*2.0*window_max_x)  #Make x have the full window width range
  t.goto(x,-window_max_y)
  t.pendown()
  t.goto(x,window_max_y)      #Y axis
  t.penup()
  t.goto(x+window_max_x*0.025,0.92*window_max_y)
  t.write("y",align="left",font=("Arial", 18, "normal"))

  raw_input("Press Enter to finish")  

###################### This is the start of your program ##############
  
def cube(x):
  the_cube=pow(x,3)
  return the_cube
  
x_array=[ ]
y_array=[ ]
for x in range(-20,20):
  y=cube(x)
  x_array=x_array+[x]
  y_array=y_array+[y]
graph_xy(x_array,y_array)  
  
  