473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

name error global name 'x' is not defined...help

Expand|Select|Wrap|Line Numbers
  1. import subprocess
  2. import sys
  3. import time
  4. import os
  5.  
  6. def main():
  7.     #Check to see if quickdraw is located in the correct palce
  8.     quickfile = file_existance()
  9.     quickdraw = subprocess.Popen(['java', '-jar', quickfile], stdin = subprocess.PIPE)
  10.     #Intro, explaining what will occur throughout program
  11.     intro()
  12.     #
  13.     x_coordinate(1)
  14.     y_coordinate(1)
  15.     initial_ball(quickdraw)
  16.  
  17.  
  18. def file_existance():
  19.         filename = raw_input("Please enter the name of the file: ")
  20.         while (not os.path.isfile(filename)):
  21.                 print "That file does not exist, try again"
  22.                 filename = raw_input("Please enter the name of the file: ")
  23.         print os.path.abspath(filename)
  24.         return filename
  25.  
  26. def intro():
  27.     print "For this assignment you will be asked to give coordinates for a ball,"
  28.     print "after you have given the coordinates, the ball will continually bounce"
  29.     print "until it runs out of energy and comes to a complete stop."
  30.  
  31. def x_coordinate(num):
  32.     num= num+1
  33.     x= int(input("Please enter the x-coordinate (between 0 and 600) where you would like the ball placed: "))
  34.     if (x <= 600) and (x >= 0):
  35.         print "Valid choice"
  36.         return x
  37.     else:
  38.         print "invalid choice, choose again please"
  39.         if num > 3:
  40.             x = 300
  41.             return x
  42.         else:
  43.             x_coordinate(num)
  44.     return x
  45.  
  46. def y_coordinate(num):
  47.     num= num+1
  48.     y= int(input("Please enter the y-coordinate (between 0 and 600) where you would like the ball placed: "))
  49.     if (y >= 0) and (y <= 600):
  50.         print "Valid choice"
  51.         return y
  52.     else:
  53.         print "invalid choice, choose again please"
  54.         if num > 3:
  55.             y = 300
  56.             return y
  57.         else:
  58.             y_coordinate(num)    
  59.  
  60.  
  61.  
  62. def initial_ball(quickdraw):
  63.     radius= 300
  64.     ball = "fillcircle" + ' ' + str(x) + ' ' + str(y) + ' ' + str(radius)
  65.     quickdraw.stdin.write(ball)
  66.     quickdraw.stdin.write("\n") 
  67.  
The error is that the global name 'x' is not defined. But I dont understand why because I returned the variable...
Nov 8 '10 #1
1 4316
bvdet
2,851 Expert Mod 2GB
You should assign x_coordinate(1) to an identifier and pass that as an additional parameter to initial_ball(). You must do the same for y_coordinate(1).

You could also do this:
Expand|Select|Wrap|Line Numbers
  1.     initial_ball(quickdraw,
  2.                  x_coordinate(1),
  3.                  y_coordinate(1))
Redefine initial_ball: def initial_ball(quickdraw, x, y):
Nov 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: NetKev | last post by:
I added a function 'warn_Admin' and defined it just before another function 'process_log'. 'process_log' calls this warn_Admin' function. However, when it gets called i get the following error...
1
by: a | last post by:
What I want --------------- I want to create a list of items from a function operating on an array of strings What I did ----------------- list= l=len(list)
2
by: a | last post by:
def fn(): for i in range(l) global count count= .... how do i declare count to be global if it is an array subsequently i should access or define count as an array error:
1
by: NachosRancheros | last post by:
Ok so I just started to program with Python about a week ago and I am trying to make a program that will take the path of a file and a shortcut command and save it to a text file. Eventually I want...
8
by: Evan | last post by:
Hi I have a short script that makes 2 calls to methods in another script as follows: import canPlaces as canp callOne=canp.addMe(3,5) callTwo=canp.estocStn()
3
by: barronmo | last post by:
I'm getting an error msg I don't understand, "global name EMR_globals is not defined", and could use some help. I've separated the application I'm building into several modules. One of the...
2
by: pythonnewb | last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was...
2
by: jmike | last post by:
I'm using some legacy code that has a user-defined exception in it. The top level program includes this line from TestRunError import * It also imports several other modules. These other...
2
by: Geared | last post by:
Hello I'm new to python (been using it all of 2 weeks) and I'm trying to write a program that compares the result of an equation using two different starting numbers that the user chooses. It also...
4
by: jorgejch | last post by:
Hello, I've started with python (3) recently. Initialy only for scripting. Now I'm trying the object oriented bit. I'm getting the following error message <Atom.Atom object at 0x7f0b09597fd0>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.