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.