473,387 Members | 1,504 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,387 software developers and data experts.

Passing variables between functions

I am a first time user, but need some urgent simple help.

I have information that is local to a function,but I want to use this information in another function called getInput. I will show example below. I have tried placing information in main, but it keeps coming up with nameA not defined.

nameA and name B appear in the printIntro, and I have obtained these values from raw_input, and they are included in print statements and work fine.

I wish to include these values in getInput()

in a print statement
print nameA "has a probability of", a (a and b are local to the getInputs)
print nameB "has a probability of", b

Bartonc or anybody else can you help

Thanks Jen
Jun 27 '07 #1
5 6203
DeMan
1,806 1GB
Hi America,

Welcome to TSDN. I'm sure you will find a wealth of information available in the various forums. These can be found by selecting a link to a drop-down list on the blue menu bar near the top of the screen. Unfortunately, I am not sure of the language you are using and can't redirect this post.

I hope the experts in the relevant forum can assist with your enquiry.
Jun 27 '07 #2
Hi,

Thanks for reply.

I am using Python Programming.
Jun 27 '07 #3
DeMan
1,806 1GB
Bartonc will be your man (as you suggested earlier)......
I will move this to the Python Forum and alert him to it.....
Jun 27 '07 #4
Bartonc will be your man (as you suggested earlier)......
I will move this to the Python Forum and alert him to it.....

Thanks for your efficiency.
Jun 27 '07 #5
bvdet
2,851 Expert Mod 2GB
I am a first time user, but need some urgent simple help.

I have information that is local to a function,but I want to use this information in another function called getInput. I will show example below. I have tried placing information in main, but it keeps coming up with nameA not defined.

nameA and name B appear in the printIntro, and I have obtained these values from raw_input, and they are included in print statements and work fine.

I wish to include these values in getInput()

in a print statement
print nameA "has a probability of", a (a and b are local to the getInputs)
print nameB "has a probability of", b

Bartonc or anybody else can you help

Thanks Jen
I am not sure what you are trying to do because you did not show us much of your code. I would suggest that you try returning values from one function into another function as arguments:
Expand|Select|Wrap|Line Numbers
  1. def printIntro(a,b):
  2.     nameA = 'Case 1'
  3.     nameB = 'Case 2'
  4.     print nameA, "has a probability of", a
  5.     print nameB, "has a probability of", b
  6.  
  7. def getInput():
  8.     a = 0.75
  9.     b = 0.5
  10.     return a, b
  11.  
  12. if __name__ == '__main__':
  13.     printIntro(*getInput())
Jun 28 '07 #6

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
3
by: jeffg | last post by:
The answer probably is staring me in the face and I don't see it, so I'll just ask. I try to limit the scope of variables and avoid global variables. But sometimes I get stumped by the following...
20
by: Gregory Piñero | last post by:
Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> ...
9
by: zholthran | last post by:
Hi folks, after reading several threads on this issue (-> subject) I fear that I got a problem that cannot easily be solved by the offered workarounds in an acceptable way, at least not with my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.