名称错误未定义全局名称"x"…help
选择 | 换行 | 行号
- import subprocess
- import sys
- import time
- import os
- 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"
- return x
- else:
- print "invalid choice, choose again please"
- if num > 3:
- x = 300
- return x
- 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"
- return y
- else:
- print "invalid choice, choose again please"
- if num > 3:
- y = 300
- return y
- else:
- y_coordinate(num)
- def initial_ball(quickdraw):
- radius= 300
- ball = "fillcircle" + ' ' + str(x) + ' ' + str(y) + ' ' + str(radius)
- quickdraw.stdin.write(ball)
- quickdraw.stdin.write("\n")
错误是未定义全局名称"x"。但我不明白为什么,因为我返回了变量。。。