def main():
	#Check to see if quickdraw is located in the correct palce
	quickfile = file_existance()
	quickdraw = subprocess.Popen(['java', '-jar', quickfile], stdin = subprocess.PIPE)
	#Intro, explaining what will occur throughout program
	intro()
	#
	x_coordinate(1)
	y_coordinate(1)
	initial_ball(quickdraw)


def file_existance():
        filename = raw_input("Please enter the name of the file: ")
        while (not os.path.isfile(filename)):
                print "That file does not exist, try again"
                filename = raw_input("Please enter the name of the file: ")
        print os.path.abspath(filename)
        return filename

def intro():
	print "For this assignment you will be asked to give coordinates for a ball,"
	print "after you have given the coordinates, the ball will continually bounce"
	print "until it runs out of energy and comes to a complete stop."

def x_coordinate(num):
	num= num+1
	x= int(input("Please enter the x-coordinate (between 0 and 600) where you would like the ball placed: "))
	if (x <= 600) and (x >= 0):
		print "Valid choice"
	else:
		print "invalid choice, choose again please"
		if num > 3:
			x = 300
		else:
			x_coordinate(num)
	return x

def y_coordinate(num):
	num= num+1
	y= int(input("Please enter the y-coordinate (between 0 and 600) where you would like the ball placed: "))
	if (y >= 0) and (y <= 600):
		print "Valid choice"
	else:
		print "invalid choice, choose again please"
		if num > 3:
			y = 300
		else:
			y_coordinate(num)	
	return y


def initial_ball(quickdraw):
	radius= 300
	ball = "fillcircle" + ' ' + str(x) + ' ' + str(y) + ' ' + str(radius)
	quickdraw.stdin.write(ball)
	quickdraw.stdin.write("\n")




main()

When I run this, gives me an error saying "name error: global name 'x' not defined" If it is true for x, I am guessing its the same for the y. I tried returning the variable but it doesnt seem to work. Help please.

What line is the error on?

Well from having a look, it seems that you haven't defined x and y in all of your functions. I just had a quick look at the last one. You mention both 'x' and 'y', but neither have been declared in the function. You need to be able to pass 'x' and 'y' into other functions. You could do this with global variables (although they are discourage), or you could fit the whole thing in a class.

Global Variables
Classes (2.7 spec)

x_coordinate and y_coordinate does exactly same thing, remove one and call_it get_coordinate (replacing all x, with neutral name, say coord) and use instead of line 8-9

x, y = get_coordinate(), get_coordinate()

Then pass x,y also to function at line 53.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.