471,349 Members | 1,173 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 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 6095
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

Post your reply

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

Similar topics

3 posts views Thread by domeceo | last post: by
3 posts views Thread by jeffg | last post: by
9 posts views Thread by zholthran | last post: by

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.