473,396 Members | 1,907 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.

I get the following error message global name error message

I get the following message when I try to run the below program: builtins.NameError: global name 'gallons' is not defined

Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     square_feet = float(input("Enter the square feet of the wall that is to be painted: "))
  3.     gallons = (square_feet/115)
  4.     paint = float(input("Enter the cost of paint per gallons: "))
  5.     labor = (gallons * 8 * 20)
  6.     price_paint = (paint + gallons)
  7.     hours = (square_feet/14.37)
  8.     total_cost = (labor + price_paint)
  9.     charges()
  10. def charges():
  11.     print ("The number of gallons of paint is", gallons)
  12.     print ("The number of hours of labor is",hours)
  13.     print ("The cost of the paint is",price_paint)
  14.     print ("The cost for labor will be",labor)
  15.     print ("The total cost for the paint job is", total_cost)
  16. main()
Sep 23 '12 #1
3 2415
bvdet
2,851 Expert Mod 2GB
The definition of gallons is local to function main() and not in the namespace of function charges(). For more information about Python's scope rules see Python documentation 9.2. Python Scopes and Namespaces.
Sep 23 '12 #2
Okay, how do you do it in 2 functions then?
Sep 23 '12 #3
bvdet
2,851 Expert Mod 2GB
Create global variables with the global statement or pass the values to function charges() as arguments.
Sep 24 '12 #4

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

Similar topics

2
by: Jerry Tovar | last post by:
I am using .net 2003. I am trying to create a C# ASP.Net webform. When I attempt to create a new ASP.Net project and place a label on my webform, build it and run the webform, I get the following...
1
by: Neil | last post by:
Hello - In every project I try to compile and run, I'm getting a parser error on global.asax (pasted below). I have rebuilt and recompiled, and this happens on every project on my machine, no...
1
by: John | last post by:
Hi When I try to get reference to my remotely hosted web service, I get the following error; Parser Error Message: Could not load type 'localhost.Global'. Source Error: Line 1: <%@...
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...
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:
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...
0
by: JB | last post by:
Lots of problems ive managed to work through, but this one is causing me much grief. Description: An error occurred during the parsing of a resource required to service this request. Please...
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...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.