473,372 Members | 1,550 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,372 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 6202
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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...

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.